I am currently trying to make an app create and write into a file in external storage. However, I get the java.io.FileNotFoundException: /storage/emulated/0/input.csv: open failed: EACCES (Permission denied)
error when trying to open the file.
I have looked around StackOverflow, and the problem is happening because I have the phone plugged into the computer for debugging purposes as the directory path is correct and I have <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
in the AndroidManifest.xml
(between <manifest>
and <application>
).
My question is, is there a way to fix this error while still having USB debugging active? I need to maintain the ADB connection and monitor the logcat, for now, to see if all parts of the app are working as expected.
For completeness' sake, here is the code I use to attempt to create a file.
File input = new File(Environment.getExternalStorageDirectory().getAbsolutePath() + "/input.csv");
FileWriter writer = new FileWriter(input);
writer.append(csvString);
writer.flush();
writer.close();