Java Utililty Methods File Size Readable Format

List of utility methods to do File Size Readable Format

Description

The list of methods to do File Size Readable Format are organized into topic(s).

Method

StringFormatFileSize(String filesize)
Make file size format
int len = 0;
int mok = 0;
int mod = 0;
String result = "";
String reverseResult = "";
String stringMok = "";
String reverseMok = "";
len = filesize.length();
...
StringformatFilesize(String filesize, int decimalPlaces)
Formats a file size string if it is a numeric representation stored in bytes.
try {
    int multipleCount = 0;
    long filesizeValue = Long.parseLong(filesize);
    long filesizeRemainder = 0;
    while (filesizeValue > 1024 && multipleCount < filesizeSuffixes.length) {
        filesizeRemainder = filesizeValue % 1024;
        filesizeValue /= 1024;
        multipleCount++;
...
StringformatFileStats(final String label, final long fileCount, final Object rawSize)
Formats an object's file statistics for display.
long size = 0;
if (rawSize != null) {
    if (rawSize instanceof Integer) {
        size = (Integer) rawSize;
    } else if (rawSize instanceof Long) {
        size = (Long) rawSize;
if (label == null || label.equals("") || label.equalsIgnoreCase("total")) {
    return String.format("%s in %s files", formatSize(size), fileCount);
return String.format("%s: %s in %s files", label, formatSize(size), fileCount);
StringformatGroup(String str, int groupSize, int lineBreak)
format Group
StringBuffer buffer = new StringBuffer();
int line = 1;
buffer.append("/*  1 */ \"");
for (int i = 0; i < str.length(); i += groupSize) {
    buffer.append(str.substring(i, i + Math.min(str.length() - i, groupSize)));
    if ((i + groupSize) % lineBreak == 0) {
        buffer.append("\" +\n/* ");
        line++;
...
StringformatIndex(int index, int totalSize)
Format a number as String that can be always be large enough to hold "totalSize" digits.
int digits = (int) (Math.ceil(Math.log(totalSize) / Math.log(10)) + .5);
String s = "" + index;
while (s.length() < digits) {
    s = "0" + s;
return s;
StringformatInt(int val, int size)
format Int
String formatter = "%0" + size + "d";
return String.format(formatter, val);
StringformatRow(String[] values, int[] sizes)
Format row.
return formatRow(" ", values, sizes);
StringformatSeperatorRow(int[] sizes)
Format seperator row.
String[] values = new String[sizes.length];
for (int i = 0; i < values.length; i++) {
    values[i] = DASHES;
return formatRow(" ", values, sizes);
StringformatShortByte(long size)
format Short Byte
return size + bytePostfix;
StringformatSize(double size)
format Size
int i;
for (i = 0; size >= 1024 && i < 4; i++) {
    size /= 1024;
return (Math.round(size * 100.0) / 100.0) + " " + SIZE_UNITS[i];