Android 获取cache缓存的目录路径

来源:互联网 发布:淘宝上牛排都是假的 编辑:程序博客网 时间:2024/06/05 12:43

转发请备注原文地址:https://www.niwoxuexi.com/blog/android00/article/224.html

Android开发中,有时需要知道cache缓存的路径。我写了一个静态类,供大家能参考

public class  CommonUtil {      /**    * 获取cache路径    *    * @param context    * @return    */   public static String getDiskCachePath(Context context) {      if (Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())             || !Environment.isExternalStorageRemovable()) {         return context.getExternalCacheDir().getPath();      } else {         return context.getCacheDir().getPath();      }   }}