Here you can find the source of humanReadableSize(long byteCount)
Parameter | Description |
---|---|
byteCount | the number of bytes |
public static String humanReadableSize(long byteCount)
//package com.java2s; //License from project: Apache License public class Main { /** Number of bytes in a kilobyte. */ public static final int KB_BYTES = 1024; /** Number of bytes in a megabyte. */ public static final long MB_BYTES = 1024 * 1024; /** Number of bytes in a gigabyte. */ public static final long GB_BYTES = 1024 * 1024 * 1024; /**//w w w . j a v a 2s . c om * Returns a human-readable (memory, file, ...) size. * @param byteCount the number of bytes * @return a human-readable size with units */ public static String humanReadableSize(long byteCount) { String result; if (byteCount / GB_BYTES > 0) { result = Long.toString(byteCount / GB_BYTES) + " GB"; } else if (byteCount / MB_BYTES > 0) { result = Long.toString(byteCount / MB_BYTES) + " MB"; } else if (byteCount / KB_BYTES > 0) { result = Long.toString(byteCount / KB_BYTES) + " kB"; } else { result = Long.toString(byteCount) + " B"; } return result; } }