I have a folder, called MyFolder, in the android device internal storage root directory. There is no external sd card mounted. The folder can be checked using says, ES file manager I want to write a file to that directory. I try the followings but seem all are not what I want. So how should sd be? Please help.
File sd = Environment.getExternalStorageDirectory();
// File sd = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS) ;
// File sd = new File( Environment.getExternalStorageDirectory().getAbsolutePath());
// File sd = Environment.getRootDirectory() ; // system
// File sd = Environment.getDataDirectory() ;
backupDBPath = "MyFolder/_subfolder/mydata.txt";
File backupDB = new File(sd, backupDBPath);
From an app, you cannot write a file anywhere you'd like on the device's internal storage, it has to be located in the app's internal directory or app cache directory.
You could write:
More infos here:
https://developer.android.com/training/data-storage/files.html
If your directory located in the internal data directory of your app, you could write the code.
From the official document: https://developer.android.com/guide/topics/data/data-storage.html#filesExternal
The device has removable(SD Card) or non-removable storage(Internal shared storage). Both are called external storage. Suppose you could create the directory in "Internal Shared storage", you could write the code below.
Note: If you have to use getExternalStorage, you should give the storage permission.