app几种文件位置的一些区别

1.实际路径:data/data/com.xx.xx/cache

mContext.getCacheDir()

2.实际路径:data/data/com.xx.xx/files 在应用信息中点击清除缓存不会清除此文件夹里的文件,点击清除数据才会清除,并清除cache文件夹内的文件

mContext.getFilesDir()

3.实际路径: sdcard/Anroid/data/com.xx.xx/cache

mContext.getExternalCacheDir()

4.实际路径:sdcard/Android/data/com.xx.xx/

mContext.getExternalFilesDir(null)

5.实际路径:sdcard/

Environment.getExternalStorageDirectory()

在应用管理里点击清除缓存会清除1,3文件夹里的数据,点击清除数据会清除上面四个文件夹里的所有数据,清除com.xx.xx下的所有数据;
1,2是包里的路径,3,4是内置sd卡的路径,/storage/sdcard0 = /storage/emulated/0/
外置sdk路径是/storage/sdcard1

/**
 * 根据传入的uniqueName获取硬盘缓存的路径地址。
 */
public static File getSdcardCacheDir(String uniqueName) {
    String cachePath;

    if (Environment.MEDIA_MOUNTED.equals(Environment
            .getExternalStorageState())
            && !Environment.isExternalStorageRemovable()) {
        if (mContext.getExternalCacheDir() != null) {//小米某些盒子经过上面的判断后,这里依然可能为空
            cachePath = mContext.getExternalCacheDir().getPath();
        } else {
            cachePath = mContext.getCacheDir().getPath();
        }
    } else {
        cachePath = mContext.getCacheDir().getPath();
    }
    return new File(cachePath + File.separator + uniqueName);
}

/**
 *
 * @param fileName
 * @return
 */
public static File getSdcardFileDir(String fileName) {
    String path;
    if (Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState()) && !Environment.isExternalStorageRemovable()) {
        File externalFilesDir = mContext.getExternalFilesDir(null);
        if (externalFilesDir != null) {
            path = externalFilesDir.getPath();
        } else {
            path = mContext.getFilesDir().getPath();
        }
    } else {
        path = mContext.getFilesDir().getPath();
    }
    return new File(path + File.separator + fileName);
}

/**
 * 清除缓存会清除的文件夹
 *
 * @param fileName
 * @return
 */
public static File getAppCacheDir(String fileName) {
    String cacheDir = mContext.getCacheDir().getPath();
    return new File(cacheDir + File.separator + fileName);
}

/**
 * 清除缓存不会清除,清除数据会清除
 *
 * @param uniqueName
 * @return
 */
public static File getAppFileDir(String uniqueName) {
    String cachePath = mContext.getFilesDir().getPath();
    return new File(cachePath + File.separator + uniqueName);
}
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值