方法一
public static String readableFileSize(long size) {
if (size <= 0) return "0";
final String[] units = new String[]{"B", "kB", "MB", "GB", "TB"};
int digitGroups = (int) (Math.log10(size) / Math.log10(1024));
return new DecimalFormat("#,##0.#").format(size / Math.pow(1024, digitGroups)) + " " + units[digitGroups];
}
方法二
public static String humanReadableByteCount(long bytes, boolean si) {
int unit = si ? 1000 : 1024;
if (bytes < unit) return bytes + " B";
int exp = (int) (Math.log(bytes) / Math.log(unit));
String pre = (si ? "kMGTPE" : "KMGTPE").charAt(exp - 1) + (si ? "" : "i");
return String.format("%.1f %sB", bytes / Math.pow(unit, exp), pre);
}
方法三
使用org.apache.commons.io.FileUtils.byteCountToDisplaySize(long size)
FileUtils.byteCountToDisplaySize(long size)
参考:
- Format file size as MB, GB etc;
- How to convert byte size into human readable format in java?;
- JavaDoc for byteCountToDisplaySize;
最新评论
能弄个电视apk 就好了
求分享站点。https://www.ziyedm.com 子夜动漫 无广告,更新及时
+62 +63 都不行 一直邮箱 验证也上不去 要么就呼叫来电 或者发送到另一台设备 但是另一台设备没有收到码 这个文章也看过了
telegram x接不到验证码