code: static public String getFormattedBytes(long bytes, String units, String format)
      {
          double num = bytes;
          String[] prefix = {"", "K", "M", "G", "T"};
          int count = 0;
  
          while(num >= 1024.0)
          {
              num = num/1024.0;
              ++count;
          }
  
          DecimalFormat f = new DecimalFormat(format);
          return f.format(num)+" "+prefix[count]+units;
      }
docs: Returns the given bytes number formatted as KBytes, MBytes or GBytes as appropriate.
  @param bytes The bytes to be converted
  @param units The units to be displayed with the converted bytes
  @param format The format to use to display the bytes
  @return The given bytes number formatted as KBytes, MBytes or GBytes as appropriate