I need some functionality where I can save a text file and an image in my device, that can somehow be accessed without the application.
For the text file I would just like to write my database in it. I need for the user to be able to later access that file. Is this possible? If so, how can I do it? As of now, I followed this tutorial, which sends me the message that is working. The issue is, cannot find the file. Where would it be? Or am I just missing something?
Here is my code for writing the file (which was as the tutorial suggested):
try {
File sdCard = Environment.getExternalStorageDirectory();
File dir = new File (sdCard.getAbsolutePath() + "/documents");
dir.mkdirs();
File myFile = new File(dir, "mysdfile.txt");
myFile.createNewFile();
FileOutputStream fOut = new FileOutputStream(myFile);
OutputStreamWriter myOutWriter =
new OutputStreamWriter(fOut);
myOutWriter.append("I am writing something on the file as a test!");
myOutWriter.close();
fOut.close();
Toast.makeText(getBaseContext(),
"Done writing SD 'mysdfile.txt'",
Toast.LENGTH_SHORT).show();
} catch (Exception e) {
Toast.makeText(getBaseContext(), e.getMessage(),
Toast.LENGTH_SHORT).show();
}
Thanks!
Edit: just to add a couple more details, the directory I am getting from the
Environment.getExternalStorageDirectory();
is /storage/emulated/0 is this what is expected? Or is there something wrong that I may be missing?