Java 实例 - 获取文件大小
作者:互联网
import java.io.File;
public class Main {
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("c:/java.txt");
System.out.println("java.txt文件大小为: " + size);
}
}
标签:文件大小,Java,File,实例,file,java,public,size 来源: https://blog.csdn.net/qq_30273575/article/details/123233390