Is it possible for android application to create several directories in internal storage for storing there different kinds of files? I need this capability, because I'll need to delete a kind of files at definite time moment in my application.
When I try to use standard Context
method openFileOutput()
and send to it filename with "/" symbol I get IllegalArgumentException
.
Tell me please what classes and methods could allow me such functionality?
To allow other apps to access files stored in this directory within internal storage, use a FileProvider with the FLAG_GRANT_READ_URI_PERMISSION attribute.
Use Context.getDir(String name, int mode) method to create or access directories in internal storage. Quote from docs:
Retrieve, creating if needed, a new directory in which the application can place its own custom data files. You can use the returned File object to create and access files in this directory. Note that files created through a File object will only be accessible by your own application; you can only set the mode of the entire directory, not of individual files.
UPD Example:
File mydir = context.getDir("mydir", Context.MODE_PRIVATE); //Creating an internal dir;
File fileWithinMyDir = new File(mydir, "myfile"); //Getting a file within the dir.
FileOutputStream out = new FileOutputStream(fileWithinMyDir); //Use the stream as usual to write into the file.
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