Here you can find the source of bytesToHuman(long size)
public static String bytesToHuman(long size)
//package com.java2s; //License from project: Open Source License public class Main { public static String bytesToHuman(long size) { if (size < 1024L) { return size + "bytes"; } else if (size < 1024L * 1024L) { return String.format("%.2fkb", (double) size / 1024L); } else if (size < 1024L * 1024L * 1024L) { return String.format("%.2fmb", (double) size / (1024L * 1024L)); } else if (size < 1024L * 1024L * 1024L * 1024L) { return String.format("%.2fgb", (double) size / (1024L * 1024L * 1024L)); }//from w ww. java 2 s.c om return String.format("%.2ftb", (double) size / (1024L * 1024L * 1024L * 1024L)); } }