Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

android

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

like image 509
Ollie C Avatar asked Feb 07 '11 20:02

Ollie C


4 Answers

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.

like image 161
CommonsWare Avatar answered Oct 20 '22 13:10

CommonsWare


In DDMS, I found my file under:

data > data > your app id > files
like image 44
Craig Zheng Avatar answered Oct 20 '22 13:10

Craig Zheng


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()
like image 3
arekolek Avatar answered Oct 20 '22 11:10

arekolek


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.

like image 2
Heiko Rupp Avatar answered Oct 20 '22 12:10

Heiko Rupp