2011-02-07 83 views
41

我不明白为什么这个答案不在Android开发人员文档中;我发现他们始终令人沮丧。Android的Context.openFileOutput()使用什么文件系统路径?

重新使用Context类的openFileOutput()方法打开文件进行写入,它写入的内部存储器文件路径是什么?

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

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

+2

data> data> your app id> files` – YumYumYum 2013-08-02 03:01:54

+2

手机需要扎根才能查看`/ data/data` – tchelidze 2017-03-21 09:07:28

回答

53

重新使用Context类的openFileOutput()方法打开文件进行写入,它写入的内部存储器文件路径是什么?

它指向ContextgetFilesDir()返回。您可以这样说,因为文档中说:

返回文件系统中使用openFileOutput(String,int)创建文件的目录的绝对路径。

+1

我希望文档清楚地说明位置可以移动,以及使用什么方法来查找位置(例如,将getFilesDir()添加到See Also部分)。非常感谢Mark,感谢您的帮助。 – 2011-02-07 20:40:35

1

此文件被写入相对于您的应用程序在设备内存中的路径。 你也许可以用ddms看看这个位置,但是当你使用这个Context.openFileOutput()时,你不应该关心任何绝对路径。

如果你想传递文件名称,你应该考虑使用external storage

16

在DDMS,我发现我下的文件:

data > data > your app id > files 
0

您可以检索文件路径通过调用Context#getFileStreamPath(String)

返回在其中一个文件中创建文件系统的绝对路径存储了openFileOutput(String, int)

然后File#getAbsolutePath()

相关问题