Java File.lastModified()

Syntax

File.lastModified() has the following syntax.

public long lastModified()

Example

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


/*from www .j a v a  2  s .co  m*/
import java.io.File;
import java.util.Date;

public class Main {
  public static void main(String[] args) {

    File f = new File("c:/test.txt");

    boolean bool = f.exists();

    // if path exists
    if (bool) {
      // returns the time file was last modified
      long millisec = f.lastModified();

      // date and time
      Date dt = new Date(millisec);

      // path
      String path = f.getPath();

      System.out.print(path + " last modified at: " + dt);
    }

  }
}