What file system path is used by Android's Context.openFileOutput()?
Re the openFileOutput() method on the Context class to open a file for writing, what internal storage file path does it write to?
It points to where getFilesDir()
on Context
returns. You can tell this because the documentation says:
Returns the absolute path to the directory on the filesystem where files created with openFileOutput(String, int) are stored.
Where does a file get saved when openFileOutput is used?
see this page : http://developer.android.com/reference/android/os/Environment.html
You can get some path to directory.
I think, if you try to use directly ApplicationContext.openFileOutput(filename, Context.MODE_WORLD_READABLE);
, the file will be create at the root of the phone, but I'm not sure, or in the /data.
Where is the data file on the android file system?
openFileOutput
returns a location not accessible trough file explorer. It should be /data/data/yourpackagename
Getting the file if openFileOutput is used
How do you get the File from openFileOutput ?
Use Context.getFilesDir()
for getting file path which is created using openFileOutput
method:
String rootDir = this.getFilesDir().getAbsolutePath();
File file = new File(rootDir + filename);
.....
intent.setData(Uri.fromFile(file));
Read .txt field data from /storage/emulated/ path in android 11
You should write to the location /storage/emulated
directory. You avhave used openFileOutput()
. It points to where getFilesDir()
on Context returns. You can tell this because the documentation says:
Returns the absolute path to the directory on the filesystem where files created with openFileOutput(String, int) are stored.
To read from your location, use openFileInput()
, the corresponding method on Context with the same filename that you had passsed to the openFileOutput()
.
In which directory is being stored a file when I use Activity.openFileOutput(myFile, Context.MODE_PRIVATE); to store it?
openFileOutput(), as the documentation states, does not take a path, the file is stored as part of your app's 'private data storage', which is inaccessible to other apps on the device. So assuming your two code snippets above are in the same Android app, you don't need to worry about the path, just pass the same file name to openFileInput() and you'll get the same data that you stored.
In your case, your file name is dbName, so in your second snippet:
is = ctx.getAssets().open(databaseName+".db");
becomes
is = ctx.openFileInput(databaseName);
which appears to be hard-coded to 'myFile' in the first snippet. I am assuming here that ctx is of type Context or a derived class such as Activity.
UPDATE: If you really need to find out the file system directory being used to store your apps private files, you can call:
ctx.getFilesDir();
or
ctx.getFileStreamPath(databaseName);
Related Topics
How to Loop Through Dynamic JSON String Recursively in Android
Which Architecture Patterns Are Used on Android
Android: How to Make Keyboard Enter Button Say "Search" and Handle Its Click
Overlap Scrolling View with Appbarlayout
Volley Android Networking Library
How to Change the Launcher Logo of an App in Android Studio
How to Securely Store Access Token and Secret in Android
When to Clear the Cache Dir in Android
What Does Ellipsize Mean in Android
Android - Spacing Between Checkbox and Text
What Are .Dex Files in Android
Android:Drawableleft Margin And/Or Padding
How to Exclude Certain Messages by Tag Name Using Android Adb Logcat
How to Animate View.Setvisibility(Gone)
How to Provide Animation When Calling Another Activity in Android