What file system path is used by Android's Context.openFileOutput()?

Android

Android Problem Overview


I can't understand why the answer to this isn't in the Android developer docs; I find them consistently frustrating.

Re the openFileOutput() method on the Context class to open a file for writing, what internal storage file path does it write to?

http://developer.android.com/reference/android/content/Context.html

http://developer.android.com/guide/topics/data/data-storage.html#filesInternal

Android Solutions


Solution 1 - Android

> 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.

Solution 2 - Android

In DDMS, I found my file under:

data > data > your app id > files

Solution 3 - Android

You can retrieve that file path by calling Context#getFileStreamPath(String):

> Returns the absolute path on the filesystem where a file created with openFileOutput(String, int) is stored.

It returns a File, so then call File#getAbsolutePath().

So summing up:

context.getFileStreamPath(name).getAbsolutePath()

Solution 4 - Android

This file is written to a path relative to your app within the devices memory. You may perhaps with ddms peek at the location, but when you are using this Context.openFileOutput(), you should not care about any absolute path.

If you want to pass the file name around you should consider using external storage.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionOllie CView Question on Stackoverflow
Solution 1 - AndroidCommonsWareView Answer on Stackoverflow
Solution 2 - AndroidCraig ZhengView Answer on Stackoverflow
Solution 3 - AndroidarekolekView Answer on Stackoverflow
Solution 4 - AndroidHeiko RuppView Answer on Stackoverflow