public static void main(String[] args) { String src = "c://test.apk"; File file = new File(src); DecimalFormat df = new DecimalFormat("0.00"); String fileSizeString = ""; if (file.length() < 1024) { fileSizeString = df.format((double) file.length()) + "B"; } else if (file.length() < 1048576) { fileSizeString = df.format((double) file.length() / 1024) + "K"; } else if (file.length() < 1073741824) { fileSizeString = df.format((double) file.length() / 1048576) + "M"; } else { fileSizeString = df.format((double) file.length() / 1073741824) + "G"; } System.out.println("==========>"+fileSizeString); }
原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/10627.html