获取文件大小(以字节为单位)
import java.io.*; public class Main {/* from 时 代 J a v a 公 众 号*/ public static void main(String[] args) { File file = new File("C://Folder/demo.txt"); long fileSize = file.length(); System.out.println("File size in bytes is: " + fileSize); System.out.println("File size in KB is : " + (double)fileSize/1024); System.out.println("File size in MB is :" + (double)fileSize/(1024*1024)); } }