Java I/O How to - Get the length of current file in long








Question

We would like to know how to get the length of current file in long.

Answer


import java.io.File;
public class MainClass {
  public static void main(String[] a) {
    File myFile = new File("C:" + File.separator);
    System.out.println(myFile.length());
  }
}

The code above generates the following result.