新增获取磁盘主机的信息
This commit is contained in:
28
src/main/java/com/mini/capi/utils/vF.java
Normal file
28
src/main/java/com/mini/capi/utils/vF.java
Normal file
@@ -0,0 +1,28 @@
|
||||
package com.mini.capi.utils;
|
||||
|
||||
public class vF {
|
||||
|
||||
|
||||
|
||||
private static final String[] UNITS = {"B", "K", "M", "G", "T", "P"};
|
||||
|
||||
|
||||
public static String format(long bytes) {
|
||||
if (bytes < 0) {
|
||||
throw new IllegalArgumentException("字节数不能为负数");
|
||||
}
|
||||
|
||||
int unitIndex = 0;
|
||||
double size = bytes;
|
||||
|
||||
while (size >= 1024 && unitIndex < UNITS.length - 1) {
|
||||
size /= 1024;
|
||||
unitIndex++;
|
||||
}
|
||||
|
||||
// 保留最多一位小数,去掉多余的 .0
|
||||
return String.format("%.1f", size).replace(".0", "") + UNITS[unitIndex];
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user