import java.io.File; import java.io.FileOutputStream; public class FileSize { /** * @param args */ public static void main(String[] args) throws Exception { File file = new File("C:\\work\\hello\\helloworld.txt"); FileOutputStream os = new FileOutputStream(file); for(int i = 0; i < 100000; i++){ os.write("This is a file size test".getBytes()); } os.close(); long length = file.length(); System.out.println("File Size " + length/1024 + "K"); System.out.println("File Size " + length/1024/1024 + "M"); } }