How to get file size in Java

In this post we will provide two examples on how to get file size in Java.

How to get file size in Java

Example 1: Using the Files class

Files.size() will return the size of the file you specified in bytes

Example 2: Using the File class

The length() method on the file object will return the size of the file in bytes.

Similar posts:

  1. How to list files in a directory
  2. How to read a file in Java
  3. How to write to a file in Java

References:

  1. Files API Documentation
  2. File API Documentation

 

 

 

Leave a Reply