How to get the size of a file?

Question:
How can you get the size of a given file in java?

Answer:
Use the method File.length().

Code:
import java.io.*;
 
public class FileSize {
   public static void main(String[] args) {
      File file = new File("FileSize.java");
      System.out.println("FileSize.java: "  + file.length());
   }
}

Output:
$ java FileSize 
FileSize.java: 201

$ ls -l FileSize.java
-rw-r--r-- 1 dennis dennis 201 Feb 28 06:51 FileSize.java