private String formatFileSize(long length) {
String result = null;
int sub_string = 0;
if (length >= 1073741824) {
sub_string = String.valueOf((float) length / 1073741824).indexOf(
".");
result = ((float) length / 1073741824 + "000").substring(0,
sub_string + 3) + "GB";
} else if (length >= 1048576) {
sub_string = String.valueOf((float) length / 1048576).indexOf(".");
result = ((float) length / 1048576 + "000").substring(0,
sub_string + 3) + "MB";
} else if (length >= 1024) {
sub_string = String.valueOf((float) length / 1024).indexOf(".");
result = ((float) length / 1024 + "000").substring(0,
sub_string + 3) + "KB";
} else if (length < 1024)
result = Long.toString(length) + "B";
return result;
}
分享到:
2012-10-25 17:16
浏览 1579
评论