Removing the "app_" prefix when creating subdirectories in the internal storage of the application
Android provides many options for storing data permanently on the device. I chose internal storage , so please do not make suggestions for SD card storage. (I've seen too many questions about internal storage that have answers on SD cards!)
I would like to create subdirectories in the internal app store directory. I followed this SO answer reproduced below.
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.
Unfortunately, this is the creation of subdirectories with the "app_" prefix. So from the example, the subdirectory looks like "app_mydir" (not ideal).
The answer to this SO question suggests that you can get rid of the "app_" prefix like this:
m_applicationDir = new File(this.getFilesDir() + "");
m_picturesDir = new File(m_applicationDir + "/mydir");
But I want to write a zip to something like /data/data/com.mypackages/files/mydir/the.zip.
So at the end, my code looks like this:
File appDir = new File(getApplicationContext().getFilesDir() + "");
File subDir = new File(appDir + "/subDir");
File outFile = new File(subDir, "/creative.zip");
But this creates another "File does not exist" error when I try this:
FileOutputStream fileStream = new FileOutputStream(outFile);
How can I (1) create a subdirectory without the "app_" prefix and (2) write a zip to it?
Also, if my first requirement is not sensible, tell me why in the comments! I'm sure the "app_" prefix has some meaning that eludes me.
source to share
Have you created catalogs?
File appDir = getApplicationContext().getFilesDir();
File subDir = new File(appDir, "subDir");
if( !subDir.exists() )
subDir.mkdir();
File outFile = new File(subDir, "creative.zip");
Please note that you should not use /
the application anywhere, just in case it changes. If you want to create your own paths use File.separator
.
source to share