import java.io.File;
public class FileSize {
public static long getFileSize(String fileName){
File file = new File(fileName);
if (!file.exists() || !file.isFile()){
System.out.println("文件不存在!!!");
return -1;
}
return file.length();
}
public static void main(String[] args) {
long size = getFileSize("copyfile");
System.out.println("文件的大小为:"+ size);
}
}
![img_fcb4b2977fa8996361f1589085fc6d79.png](https://yqfile.alicdn.com/img_fcb4b2977fa8996361f1589085fc6d79.png?x-oss-process=image/resize,w_1400/format,webp)