Android的Context.openFileOutput()使用什么文件系统路径?

时间:2020-12-22 04:05:13

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

我无法理解为什么答案不在Android开发者文档中;我发现他们一直很沮丧。

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

重新使用Context类上的openFileOutput()方法来打开要写入的文件,它写入哪个内部存储文件路径?

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

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

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

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

4 个解决方案

#1


55  

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

重新使用Context类上的openFileOutput()方法来打开要写入的文件,它写入哪个内部存储文件路径?

It points to where getFilesDir() on Context returns. You can tell this because the documentation says:

它指向Context返回的getFilesDir()的位置。您可以这样说,因为文档说:

Returns the absolute path to the directory on the filesystem where files created with openFileOutput(String, int) are stored.

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

#2


16  

In DDMS, I found my file under:

在DDMS中,我发现我的文件位于:

data > data > your app id > files

#3


1  

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.

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

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

如果要传递文件名,应考虑使用外部存储。

#4


0  

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

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

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

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

And then File#getAbsolutePath().

然后是File#getAbsolutePath()。

#1


55  

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

重新使用Context类上的openFileOutput()方法来打开要写入的文件,它写入哪个内部存储文件路径?

It points to where getFilesDir() on Context returns. You can tell this because the documentation says:

它指向Context返回的getFilesDir()的位置。您可以这样说,因为文档说:

Returns the absolute path to the directory on the filesystem where files created with openFileOutput(String, int) are stored.

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

#2


16  

In DDMS, I found my file under:

在DDMS中,我发现我的文件位于:

data > data > your app id > files

#3


1  

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.

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

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

如果要传递文件名,应考虑使用外部存储。

#4


0  

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

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

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

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

And then File#getAbsolutePath().

然后是File#getAbsolutePath()。