清华大佬耗费三个月吐血整理的几百G的资源,免费分享!....>>>
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); }