I am having trouble writing to a text file in my android project. I am using the following functions to try to write to a file.
String filename = "test.txt"; helperFileWriter = new FileWriter(filename, false); fileOut = new FileOutputStream(fileName, append); printWriter = new PrintWriter(fileOut, false); this(new BufferedWriter(new OutputStreamWriter(out)), autoFlush); se = StreamEncoder.forOutputStreamWriter(out, this, (String)null);
I am getting 2 errors depending on where I search for the file:
open failed: ENOENT (No such file or directory)
open failed: EROFS (Read-only file system)
My directory structure for this project is:
- TestProject - test (Where the app is intended to be run from) - test.txt (TXT FILE BEING WRITTEN TO) - app - build - libs - src - main - configuration_files - java - com.example.textproject - FirstFragment.java - MainActivity.java - SecondFragment.java - controller - JAVA CLASS THAT WRITES TO FILE - res - AndroidManifest.xml
I assumed that setting the "Working directory" setting to the test directory would make the app run from there (Unsure if this is how that setting works, See screenshot below). There are several other configuration files in the test directory and that is why I am trying to run from there. Is the issue I'm running into being cause because the emulator I am using is not rooted, or am I doing something else wrong?