programming-examples/java/Basics/How to get a files size in bytes.java

16 lines
524 B
Java
Raw Normal View History

2019-11-18 14:44:36 +01:00
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("File doesn\'t exist");
return -1;
}
return file.length();
}
public static void main(String[] args) {
long size = getFileSize("c:/java.txt");
System.out.println("Filesize in bytes: " + size);
}
}