What File System Path Is Used by Android's Context.Openfileoutput()

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



Leave a reply



Submit