Here you can find the source of formatFileSize(Long sizeBytes)
Parameter | Description |
---|---|
bytes | a parameter |
public static String formatFileSize(Long sizeBytes)
//package com.java2s; import java.text.DecimalFormat; public class Main { /**/*w w w . ja v a 2s. co m*/ * * @param bytes * @return */ public static String formatFileSize(Long sizeBytes) { String size = ""; try { double dSize = (double) sizeBytes; if (dSize >= 1024) { dSize /= 1024; size = "K"; if (dSize >= 1024) { dSize /= 1024; size = "M"; } } size = new DecimalFormat("0.00").format(dSize) + size; } catch (Exception e) { size = sizeBytes.toString(); } return size; } }