Given a file and we have to get the file size using Java program.
File.length()
This is a method of "File" class, which returns the file’s length (file size) in bytes.
In this program, we are using a file named "includehelp.txt" which is stored in "E:\" in my system, program will get its size in bytes and then we will convert file size in kilobytes and megabytes.
Program to get size of given file in Java
Output