Writing To External Storage Filenotfoundexception
I am attempting to write a file to external storage in android. I keep getting the error, 'java.io.FileNotFoundException: /mnt/sdcard/Survey.txt (Is a directory).' The method tha
Solution 1:
After doing a few more hours of research on this topic, I found a place were another person had posted a different way of doing this, and it is as follows:
StringfileName= surveyName + ".csv";
Stringheadings="Hello, world!";
Filepath= Environment.getExternalStorageDirectory();
Filefile=newFile(path, fileName);
path.mkdirs();
OutputStreamos=newFileOutputStream(file);
os.write(headings.getBytes());
Solution 2:
You may find that the file you are trying to write to is actually a directory. Find the file/directory and delete it.
I ran into this when I was first working with files. I called File.mkdirs() expecting it to just create the directories, but it created a directory with the filename that I specified.
When I create files I use two File objects. The first references just the path, and I call mkdirs(). The second then references the file.
//create pathFiledirectoryFile=newFile(Environment.getExternalStorageDirectory(), "");
directoryFile.mkdirs();
//create fileFileoutFile=newFile(Environment.getExternalStorageDirectory(), filename);
Solution 3:
Another reason could be mkdirs returns false anyway in Android Q please check this
Post a Comment for "Writing To External Storage Filenotfoundexception"