I am trying to access a file that i fill thanks to my app. I am storing it on my phone's memory, but not on my app's internal memory.
My problem is that the file doesn't exist when I open it on my PC (with phone connected via USB). But it is available and not empty when I open it directly from my smartphone.
I need this file to be available on my computer.
On my manifest:
READ_EXTERNAL_STORAGE
WRITE_EXTERNAL_STORAGE
I have tried this way:
FileWriter outFile = new FileWriter(Environment.getExternalStoragePublicDirectory("my_app/data/file.txt");
PrintWriter out = new PrintWriter(outFile);
out.append("text");
out.flush();
out.close();
And also this way:
File file = Environment.getExternalStoragePublicDirectory("my_app/data/file.txt");
FileOutputStream outputStream = context.openFileOutput(file, Context.MODE_WORLD_READABLE);
PrintStream printStream = new PrintStream(outputStream);
printStream.println(text);
printStream.close();
Another way..
File file = Environment.getExternalStoragePublicDirectory("my_app/data/file.txt");
FileWriter outFile = new FileWriter(file);
BufferedWriter buf = new BufferedWriter(outFile);
buf.write("hey");
buf.close();
outFile.close();
Some of those solutions work, but only on my phone so it isn't world readable, others just don't work...
What is the difference between OutPutStreamWriter
, FileWriter
, BufferedWriter
, FileOutputStream
, PrintWriter
, ...? Which one do I have to choose?
How do I manage to create my public file in order to access it directly from my computer?
Thank you for your help!