首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

文件大小变换

2012-12-24 
文件大小转换public String FormateSize(long size) {double baseKB 1024, baseMB 1024 * 1024, baseG

文件大小转换
public String FormateSize(long size) {
double baseKB = 1024, baseMB = 1024 * 1024, baseGB = 1024 * 1024 * 1024;
String strSize = "";
if (size < baseKB) {
strSize = Long.toString(size) + "B";
} else if (size > baseKB && size < baseMB) {
strSize = Double.toString(size / baseKB).substring(0, 4) + "KB";
} else if (size > baseMB && size < baseGB) {
strSize = Double.toString(size / baseMB).substring(0, 4) + "MB";
} else if (size > baseGB) {
strSize = Double.toString(size / baseGB).substring(0, 4) + "GB";
}

if (strSize.indexOf(".") == 3)
strSize = strSize.replace(".", "");
return strSize;
}

热点排行