파일 용량 표시...

public String readableFileSize(String sizeText) { 
    long size = Long.parseLong(sizeText); 		
    if (size <= 0) { 			
        return "0"; 		
    }  		
    
    final String[] units = new String[] { "B", "KB", "MB", "GB", "TB" }; 		
    int digitGroups = (int) (Math.log10(size) / Math.log10(1024)); 		
    return new DecimalFormat("#,##0.#")
             .format(size / Math.pow(1024, digitGroups)) + " " + units[digitGroups]; 
}

참고... http://stackoverflow.com/questions/3263892/format-file-size-as-mb-gb-etc

 

댓글