Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/sockets/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android FileOutputStream错误异常_Android_Fileoutputstream - Fatal编程技术网

Android FileOutputStream错误异常

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

嗨,我在save=newfileoutputstream(路径+文件名)中遇到错误; 我不知道该怎么做,是媒体应用程序,这个功能假设应用程序应该将歌曲保存为铃声

 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;