Android FileOutputStream错误异常
嗨,我在save=newfileoutputstream(路径+文件名)中遇到错误; 我不知道该怎么做,是媒体应用程序,这个功能假设应用程序应该将歌曲保存为铃声Android FileOutputStream错误异常,android,fileoutputstream,Android,Fileoutputstream,嗨,我在save=newfileoutputstream(路径+文件名)中遇到错误; 我不知道该怎么做,是媒体应用程序,这个功能假设应用程序应该将歌曲保存为铃声 public boolean saveas(int type, int position) { Log.i("ramiro", "entro saveas"); byte[] buffer = null; InputStream fIn = getBaseContext().getResources().ope
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;
}
替换这个
FileOutputStream save;
与
以下是您的问题:
- 缓冲区大小为0,该如何工作
- 即使提高缓冲区大小,也只能读取一个缓冲区。你需要一个循环
- 确保标题不为空
- 确保您有在外部存储器上写入的权限
我不知道该做什么
,是媒体应用程序
,此功能假定
。。。你能把你的想法弄清楚吗?确切的异常是什么?不打印就不要捕获异常。
FileOutputStream save = null;