我在save = new FileOutputStream(path + filename)中遇到错误; 我不知道该做什么,是媒体应用,这个功能假设应用程序应该将歌曲保存为铃声
public boolean saveas(int type, int position) {
Log.i("ramiro", "entro saveas");
byte[] buffer = null;
InputStream fIn = getBaseContext().getResources().openRawResource(
s1[position]);
int size = 0;
try {
size = fIn.available();
buffer = new byte[size];
fIn.read(buffer);
fIn.close();
} catch (IOException e) {
Log.i("ramiro", "error1 try");
return false;
}
String path = Environment.getExternalStorageDirectory().getPath()
+ "/media/audio/ringtones/";
String filename = title[position];
Log.i("ramiro", "filename: " + filename);
boolean exists = (new File(path)).exists();
if (!exists) {
new File(path).mkdirs();
}
FileOutputStream save;
try {
save = new FileOutputStream(path + filename); //error
save.write(buffer);
save.flush();
Log.i("ramiro", "paso flush");
save.close();
} catch (FileNotFoundException e) {
Log.i("ramiro", "try2 filenotfoundexception");
return false;
} catch (IOException e) {
Log.i("ramiro", "try2 ioexception");
return false;
}
答案 0 :(得分:0)
替换此
FileOutputStream save;
与
FileOutputStream save = null;
答案 1 :(得分:0)
以下是您的问题:
此外,如果您的代码崩溃,您添加了//错误评论: