You can get the size of a file in bytes using the length() method of the File class.
File myFile = new File("myfile.txt"); long fileLength = myFile.length();
If the actual File does not exist, the length() method returns zero.
If it is a directory name, the return value is not specified.
The return type of the length() method is long, not int.
import java.io.File; public class Main { public static void main(String[] args) { File myFile = new File("Main.java"); long fileLength = myFile.length(); System.out.println(fileLength); }/* w w w .ja va 2s .co m*/ }