Get File Size Java

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:

Get File Size Java

 

For more information please refer oracle documentation here

Leave a Reply

Your email address will not be published. Required fields are marked *