Java Android GetFileDir()vs getDir()-我用什么来保存应用程序中的文件私人数据?

Java Android GetFileDir()vs getDir()-我用什么来保存应用程序中的文件私人数据?,java,android,Java,Android,我知道这个问题很相似: 但是,当我只想将文件保存在我的私人数据中时,我仍然不确定该使用什么 对于目录,我应该只使用data/data/com.test.myapp?这会使我的申请成为私人的吗 // Gets the absolute path to the filesystem directory where your internal files are saved. getFilesDir() // Creates (or opens an existing) directory with

我知道这个问题很相似:

但是,当我只想将文件保存在我的私人数据中时,我仍然不确定该使用什么

对于目录,我应该只使用
data/data/com.test.myapp
?这会使我的申请成为私人的吗

// Gets the absolute path to the filesystem directory where your internal files are saved.
getFilesDir()

// Creates (or opens an existing) directory within your internal storage space.
getDir()
我还尝试阅读了一些Commonware开源项目,但我想我对整个
getExternalFilesDir()
更加困惑,因为Android不是在一定的api级别之后将内部存储(非SD卡)称为“外部”存储吗

当我只是想将文件保存在我的私人数据中时,我仍然不确定该使用什么

getFilesDir()
将很好地工作

对于目录,我应该只使用data/data/com.test.myapp吗

从不硬编码目录

这会使我的申请成为私人的吗

// Gets the absolute path to the filesystem directory where your internal files are saved.
getFilesDir()

// Creates (or opens an existing) directory within your internal storage space.
getDir()
getFilesDir()
对您的应用程序是私有的(例外:已在设备上建立根目录并以超级用户权限运行应用程序的用户)

我不知道
getDir()
有什么真正好的用途,我也不推荐它

因为安卓不是将内部存储(非SD卡)称为特定api级别之后的“外部”存储吗

外部存储在Android 1.0之前就已经存在了

内部存储大致上意味着“应用程序私有”(除非您采取特定步骤使其非私有)。外部存储大致意味着“对用户和其他应用可见”


在:-)中,您将在“资产、文件和数据解析”一章中找到有关内部和外部存储的更多详细信息。

getFilesDir()本质上是getDir(“文件”)。这是一个放置应用程序私有数据的好地方。清晰简洁。一如既往。再次感谢。另外,我买过的最好的书=)+1,但最好不要硬编码目录,因为不同的android设备/版本的android将文件放在不同的地方。这尤其棘手,因为它可能在您正在测试的任何设备上工作,只是为了在您在其他手机上尝试它的那一刻中断。@Prime:虽然通常使用的是
/data/data/your.package.name/
,但设备肯定会做一些奇怪的事情。此外,Android 4.2+将在平板电脑上使用不同的二级帐户位置
getFilesDir()
消除了这些问题,并缩短了启动时间。:-)