This code will print the size of a file in bytes to the console.
import java.io.File; public class FileSize { /** * JavaProgrammingForums.com */ public long getFileSize(String filename) { File file = new File(filename); if (!file.exists() || !file.isFile()) { System.out.println("File does not exist"); return -1; } // Code to get file size return[B] file.length();[/B] } public static void main(String[] args) { FileSize fs = new FileSize(); long size = fs.getFileSize("myFile.txt"); System.out.println("File size in bytes " + size); } }