数据存储在我们android开发中是不可避免的,而且,我们也都知道数据存储的方式,文件存储,SharedPreference,数据库存储等。但是应该也有一部分人, 只是知道这些存储方式,或者说只知道怎么用,但是不知道具体被保存在什么地方。本篇文章将详细分析这三种存储方式。
算了不卖关子了,其实,在我看来数据存储,或者说数据的持久化,就分为两类。内部存储,外部存储。
内部存储空间
路径:data/data/包名
1 、getFileDir()
路径:data/data/包名/file
/**
* Returns the absolute path to the directory on the filesystem where files
* created with {@link #openFileOutput} are stored.
* <p>
* The returned path may change over time if the calling app is moved to an
* adopted storage device, so only relative paths should be persisted.
* <p>
* No additional permissions are required for the calling app to read or
* write files under the returned path.
*
* @return The path of the directory holding application files.
* @see #openFileOutput
* @see #getFileStreamPath
* @see #getDir
*/
public abstract File getFilesDir();
通过官方注释我们可以看到,这个方法返回一个绝对路径,这个绝对路径是有openFilePutput()方法创建的文件。重要的是最后一句,当在这个路径下调用程序来进行读写操作的时候,是不需要任何额外的权限的。也就是说,我们在使用内部存储的方法存储数据的时候,不需要用在manifest文件中声明权限,也不需要考虑android6.0的运行时权限的。
1.1 openFileOutput()
根据上面的