檢視快取大小和清除快取

2021-09-25 00:15:01 字數 1430 閱讀 6309

public

class

cleandatautils

return

getformatsize

(cachesize);}

// 獲取檔案

--> sdcard/android/data/你的應用的包名/files/ 目錄,一般放一些長時間儲存的資料

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

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 =

newbigdecimal

(terabytes)

;return result4.

setscale(2

, bigdecimal.round_half_up)

.toplainstring()

+"t";}

/** * 清空快取

* @param context

*/public

static

void

clearallcache

(context context)

}private

static

boolean

deletedir

(file dir)}}

return dir.

delete()

;}/** * * 按名字清除本應用資料庫 * *

** @param context

* @param dbname

*/public

static

void

cleandatabasebyname

(context context, string dbname)

}

Android獲取快取大小和清除快取功能

拿去可以直接用 一 清除資料都有哪些 1 file 普通檔案儲存,對應路徑 data data com.files 應用內檔案 得到的方法getfiledir 2 database 資料庫檔案 db檔案 對應路徑 data data com.database 應用資料庫 3 shareprefere...

iOS 計算快取檔案大小和清除快取

獲得快取路徑 self.cachespath nssearchpathfordirectoriesindomains nscachesdirectory,nsuserdomainmask,yes lastobject 快取管理 pragma mark 單個檔案的大小 long long filesi...

Xcode計算快取檔案大小和清除快取

獲得快取路徑 self.cachespath nssearchpathfordirectoriesindomains nscachesdirectory,nsuserdomainmask,yes lastobject 快取管理 pragma mark 單個檔案的大小 long long filesi...