Java File Size Readable Format formatSize(long bytes)

Here you can find the source of formatSize(long bytes)

Description

format Size

License

Open Source License

Declaration

public static String formatSize(long bytes) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    public static String formatSize(long bytes) {
        long factor = 1;
        int pos = 0;
        String[] abrv = { "B", "KB", "MB", "GB" };
        for (int i = 0; i < 4; i++) {
            if (bytes / factor == 0) {
                pos = i - 1;/*from w w  w.  ja  v a  2 s. c om*/
                break;
            }
            factor *= 1024;
        }
        return "" + ((bytes * 1024) / factor) + " " + abrv[pos];
    }
}

Related

  1. formatRow(String[] values, int[] sizes)
  2. formatSeperatorRow(int[] sizes)
  3. formatShortByte(long size)
  4. formatSize(double size)
  5. formatSize(Integer size)
  6. formatSize(long bytes, String b, String kb, String mb, String gb)
  7. formatSize(long size)
  8. formatSize(long size)
  9. formatSize(long size)