long bytes = 2048; String size = FileUtils.byteCountToDisplaySize(bytes); System.out.println("Size: " + size); // Output: Size: 2 KB
long bytes = 1024 * 1024 * 1025; // 1 GB + 1 byte String size = FileUtils.byteCountToDisplaySize(bytes); System.out.println("Size: " + size); // Output: Size: 1.00 GBThis example converts 1 GB + 1 byte to a human-readable string "1.00 GB". In both examples, the byteCountToDisplaySize method is called with a long value representing the byte count. The method returns a string representing the size in a human-readable format. The package library used in these examples is org.apache.commons.io.FileUtils.