Skip to content
This repository has been archived by the owner on Mar 8, 2024. It is now read-only.

show also the filesize (in human readable values) #30

Open
zoff99 opened this issue Feb 2, 2017 · 1 comment
Open

show also the filesize (in human readable values) #30

zoff99 opened this issue Feb 2, 2017 · 1 comment

Comments

@zoff99
Copy link

zoff99 commented Feb 2, 2017

can you make an option that also show the sizes of files?
if possible in humanreadable format (Bytes, KiB, MiB .... )

@alexeyvasilyev
Copy link
Contributor

The following function can be used for that

    // http://stackoverflow.com/questions/3758606/how-to-convert-byte-size-into-human-readable-format-in-java
    public static String humanReadableByteCount(long bytes) {
        int unit = 1024;
        if (bytes < unit) return bytes + "B";
        int exp = (int) (Math.log(bytes) / Math.log(unit));
        char pre = "KMGTPE".charAt(exp-1);
        if (pre == 'K' || pre == 'M')
            return String.format(Locale.US, "%d%sB", (int)(bytes / Math.pow(unit, exp)), pre);
        else
            return String.format(Locale.US, "%.1f%sB", bytes / Math.pow(unit, exp), pre);
    }

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants