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