新增获取磁盘主机的信息

This commit is contained in:
2025-08-24 21:42:47 +08:00
parent da2b2cf14c
commit a4e576f27d
3 changed files with 34 additions and 6 deletions

View 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];
}
}