轉發請備註原文地址: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(); } } }