Java File.length()

Syntax

File.length() has the following syntax.

public long length()

Example

In the following code shows how to use File.length() method.


/*w  w  w  .  ja v  a  2  s  .c o  m*/
import java.io.File;

public class Main {
  public static void main(String[] args) {
    File f = new File("c:/test.txt");

    boolean bool = f.exists();

    if (bool) {
      long len = f.length();
      String path = f.getPath();
      System.out.print(path + " file length: " + len);
    }

  }
}