I have used many times openFileOutput
.
Example:
FileOutputStream fileOutputStream = openFileOutput(fileName, Context.MODE_PRIVATE);
Now I noticed that all the files using openFileOutput
method will be placed in the private app files
directory.
It looks like:
/data/data/com.my.app.app/files/example.txt
How can I replace this method to store the Files on subdirectory?
Example:
/data/data/com.my.app.app/files/subdirectory/example.txt
How can I replace this method to store the Files on subdirectory?
Replace:
FileOutputStream fileOutputStream = openFileOutput(fileName, Context.MODE_PRIVATE);
with:
File dir=new File(getFilesDir(), dirName);
dir.mkdirs();
FileOutputStream fileOutputStream = new FileOutputStream(new File(dir, fileName));
where dirName
is the name of your desired subdirectory.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With