public static String formatFileSize(int bytes){
  if (bytes <= 0)   return null;
  if (bytes < 1024) {
    return bytes + "B";
  }
 else   if (bytes < 1024 * 1024) {
    return String.format("%.1f KB",bytes / 1024.0);
  }
 else   if (bytes < 1024 * 1024 * 1024) {
    return String.format("%.1f MB",bytes / (1024.0 * 1024.0));
  }
 else {
    return String.format("%.1f GB",bytes / (1024.0 * 1024.0 * 1024.0));
  }
}

public static String formatFileSize ( int bytes ) { if ( bytes <= 0 ) return null ; if ( bytes < 1024 ) { return bytes + "B" ; } else if ( bytes < 1024 * 1024 ) { return String . format ( "%.1f KB" , bytes / 1024.0 ) ; } else if ( bytes < 1024 * 1024 * 1024 ) { return String . format ( "%.1f MB" , bytes / ( 1024.0 * 1024.0 ) ) ; } else { return String . format ( "%.1f GB" , bytes / ( 1024.0 * 1024.0 * 1024.0 ) ) ; } }
formats a file size , iso prefixes
