Get File Size Java
To get file size in java using File class length method as shown below in sample java program:
- Sample java program:
package com.javahonk; import java.io.File; public class GetFileSize { public static void main(String[] args) { File file = new File("C:\\JavaHonk\\zip\\SpringMVCRESTFulService.7z"); double size = file.length(); System.out.println("File size in byte : "+size); System.out.println("File size in kb : "+size/1000); System.out.println("File size in mb : "+size/1000000); } }
- Output:
For more information please refer oracle documentation here