将java字节自动转为"B", "KB", "MB", "GB", "TB"等

//字节转换
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];
}

posted @ 2018-12-24 09:13  sunseeker  阅读(1889)  评论(0编辑  收藏  举报