14、Android 文件存储

数据存储在我们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()
根据上面的

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值