UploadFileUtils.java
681 Bytes
package cn.com.polysoft.utils;
import java.text.DecimalFormat;
public class UploadFileUtils {
//计算文件大小
public static String getFileSize(long filesize){
String size = "";
DecimalFormat df = new DecimalFormat("#.00");
if (filesize < 1024) {
size = df.format((double) filesize) + "BT";
} else if (filesize < 1048576) {
size = df.format((double) filesize / 1024) + "KB";
} else if (filesize < 1073741824) {
size = df.format((double) filesize / 1048576) + "MB";
} else {
size = df.format((double) filesize / 1073741824) + "GB";
}
return size;
}
}