1

i am trying to pick an audio file and save it , but i am getting ENOENT , yet i use the same code with image and it works fine !!!!! \n i am using file provider to create/save files and it works more than probably . how can the same code work with images yet not with audio : \n here is some code examples \n

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);

    if(requestCode == 0  && resultCode == RESULT_OK) {
        Uri resultUri = data.getData();
            saveFile(resultUri);
    }
}

and to save the file i use :

File dirPath = new File(Environment.getExternalStorageDirectory(),"Moch/WAR/");
    File file = new File(dirPath, "notification.mp3");

    String sourceFilename = resultUri.getPath();

    BufferedInputStream bis = null;
    BufferedOutputStream bos = null;

    try {
        if(!file.exists())
            if (!file.createNewFile())
                Toast.makeText(notificationsSettings.this,"Unable to make sound File",Toast.LENGTH_LONG).show();
        if(file.exists()) {
            bis = new BufferedInputStream(new FileInputStream(sourceFilename));
            bos = new BufferedOutputStream(new FileOutputStream(file, false));
            byte[] buf = new byte[1024];
            bis.read(buf);
            do {
                bos.write(buf);
            } while (bis.read(buf) != -1);
        }
    } catch (IOException e) {
        e.printStackTrace();
    } finally {
        try {
            if (bis != null) bis.close();
            if (bos != null) bos.close();
            mProgressDialog.dismiss();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

and this is the doomed error line : \n /document/audio:266: open failed: ENOENT (No such file or directory)

0 Answers0