mirror of
https://github.com/Hello-hao/Tbed.git
synced 2024-04-21 12:32:10 +00:00
重构版功能实现
This commit is contained in:
@@ -3,6 +3,7 @@ package cn.hellohao.utils;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.io.*;
|
||||
import java.text.DecimalFormat;
|
||||
|
||||
public class SetFiles {
|
||||
// 转换文件方法
|
||||
@@ -54,7 +55,24 @@ public class SetFiles {
|
||||
return file;
|
||||
}
|
||||
|
||||
|
||||
//文件大小单位转换
|
||||
public static String readableFileSize(long fileS) {
|
||||
if(fileS==0){
|
||||
return "0B";
|
||||
}
|
||||
DecimalFormat df = new DecimalFormat("#.00");
|
||||
String fileSizeString = "";
|
||||
if (fileS < 1024) {
|
||||
fileSizeString = df.format((double) fileS) + "B";
|
||||
} else if (fileS < 1048576) {
|
||||
fileSizeString = df.format((double) fileS / 1024) + "K";
|
||||
} else if (fileS < 1073741824) {
|
||||
fileSizeString = df.format((double) fileS / 1048576) + "M";
|
||||
} else {
|
||||
fileSizeString = df.format((double) fileS / 1073741824) + "G";
|
||||
}
|
||||
return fileSizeString;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user