Java tutorial
import java.io.File; public class Main { public static void main(String[] args) { File file = new File("C:/demo.txt"); long fileSize = file.length(); System.out.println(fileSize + " bytes"); System.out.println((double) fileSize / 1024 + " KB"); System.out.println((double) fileSize / (1024 * 1024) + "MB"); } }