Android 保存到内部存储器的文件列表

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11239202/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-20 06:27:59  来源:igfitidea点击:

List of files of saved to the internal storage

android

提问by Snake

My android application is saving some stats to internal storage. Each file name is in the format of "appname-currentDate"

我的 android 应用程序正在将一些统计信息保存到内部存储中。每个文件名的格式为“appname-currentDate”

I was wondering:

我想知道:

  1. When I save to internal storage, is there a specific folder assigned to my app, or are my files saved along with files from other applications in the same directory.
  2. Is there a way to know the list of files saved by my application to the internal storage
  1. 当我保存到内部存储时,是否有一个特定的文件夹分配给我的应用程序,或者我的文件是否与来自同一目录中的其他应用程序的文件一起保存。
  2. 有没有办法知道我的应用程序保存到内部存储的文件列表

Thank you so much.

非常感谢。

回答by Sebastian

1) Depends on which method you use to get the file handle. Normally files are stored in an application specific directory, eg. /data/data/[your.package.name]/. The files in that directory are only readable by your application.

1)取决于您使用哪种方法来获取文件句柄。通常文件存储在特定于应用程序的目录中,例如。/data/data/[your.package.name]/。该目录中的文件只能由您的应用程序读取。

2) Use the getFilesDir()method in your Activityto get a Filehandle and use the listFiles()on it to get an array of Filerepresenting all files in your application data folder.

2)在您的Activity 中使用getFilesDir()方法获取文件句柄,并在其上使用listFiles()获取代表应用程序数据文件夹中所有文件的File数组。

Further reading: http://developer.android.com/guide/topics/data/data-storage.html

进一步阅读:http: //developer.android.com/guide/topics/data/data-storage.html

回答by user370305

1-When I save to internal storage, is there a specific folder assigned to my app, or are my files saved along with files from other applications in the same direcotry.

By default, files saved to the internal storage are private to your application and other applications cannot access them (nor can the user).

默认情况下,保存到内部存储的文件对您的应用程序是私有的,其他应用程序无法访问它们(用户也不能)。

And files are stored in /data/data/<package_name>/filesdirectory. Particular for your application package.

并且文件存储在/data/data/<package_name>/files目录中。特别适用于您的应用程序包。

2- Is there a way to know the list of files saved by my application to the internal storage.

use method getFilesDir()

使用方法getFilesDir()

Gets the absolute path to the filesystem directory where your internal files are saved.

获取保存内部文件的文件系统目录的绝对路径。

For more information look at Android - Internal Storage

有关更多信息,请查看Android - 内部存储

回答by Nirali

Your files will be saved in data/data/your.package.comthis folder. your.package.comis your package name.

您的文件将保存在data/data/your.package.com这个文件夹中。your.package.com是你的包名。

You can see that in ddms. If you use eclipse and run emulator or device you can see your files in eclipse -> ddms tab

您可以在 ddms 中看到这一点。如果您使用 eclipse 并运行模拟器或设备,您可以在 eclipse -> ddms 选项卡中看到您的文件

enter image description here

在此处输入图片说明