-
Log.w(TAG,“FileNotFoundException”);
-
} catch (IOException e) {
-
Log.w(TAG,“IOException”);
-
}
-
}
- 计算sdcard上的空间:
[java] view plain copy
-
/**
-
* 计算sdcard上的剩余空间
-
* @return
-
*/
-
private int freeSpaceOnSd() {
-
StatFs stat = newStatFs(Environment.getExternalStorageDirectory() .getPath());
-
double sdFreeMB = ((double)stat.getAvailableBlocks() * (double) stat.getBlockSize()) / MB;
-
return (int) sdFreeMB;
-
}
- 修改文件的最后修改时间
[java] view plain copy
-
/**
-
* 修改文件的最后修改时间
-
* @param dir
-
* @param fileName
-
*/
-
private void updateFileTime(String dir,String fileName) {
-
File file = new File(dir,fileName);
-
long newModifiedTime =System.currentTimeMillis();
-
file.setLastModified(newModifiedTime);
-
}
- 本地缓存优化
[java] view plain copy
-
/**
-
*计算存储目录下的文件大小,当文件总大小大于规定的CACHE_SIZE或者sdcard剩余空间小于FREE_SD_SPACE_NEEDED_TO_CACHE的规定
-
* 那么删除40%最近没有被使用的文件
-
* @param dirPath
-
* @param filename
-
*/
-
private void removeCache(String dirPath) {
-
File dir = new File(dirPa