清除快取幫助類

2021-08-26 12:09:40 字數 1247 閱讀 3433

在android中清除快取的功能是較為常見的。

public class

cleanmessagehelper

return getformatsize(cachesize);

}/**

* @param context

* 刪除快取

*/public static void clearallcache(context context)

}private static boolean deletedir(file dir) }}

}if (dir == null) else

}/**

* 獲取檔案

* context.getexternalfilesdir() --> sdcard/android/data/你的應用的包名/files/

* 目錄,一般放一些長時間儲存的資料

* context.getexternalcachedir() -->

* sdcard/android/data/你的應用包名/cache/目錄,一般存放臨時快取資料

* @param file

* @return

*/public static long getfoldersize(file file) throws exception else }}

} catch (exception e)

return size;

}/**

* 格式化單位

* 計算快取的大小

* @param size

* @return

*/public static string getformatsize(double size)

double megabyte = kilobyte / 1024;

if (megabyte < 1)

double gigabyte = megabyte / 1024;

if (gigabyte < 1)

double terabytes = gigabyte / 1024;

if (terabytes < 1)

bigdecimal result4 = new bigdecimal(terabytes);

return result4.setscale(2, bigdecimal.round_half_up).toplainstring()

+ "tb";

}}

清除快取類

author xly 清除快取類 public class clearcachedatautil param context 清除本應用的所有資料庫檔案 data data com.cihi databases public static void cleandatabases context co...

C 公共類 快取幫助類 (備忘)

using system using system.collections.generic using system.text using system.threading namespace librarycommon endregion region work method static voi...

Android 清除快取輔助類的封裝

清除快取輔助類 清除cache中快取的 如果是清除資料,後期可增加 created by panda on 2020 05 07 public class clearcacheutils string formatfilesize formatfilesize filesize return for...