File lastModified() in Java

lastModified(): This method is available in the java.io.File class of Java.

Syntax:

long java.io.File.lastModified()

This method returns the time that the file denoted by this abstract pathname was last modified.

Parameters: NA

Returns: A long value representing the time the file was last modified, measured in milliseconds since the epoch(00:00:00 GMT, January 1, 1970), or 0L if the file does not exist or if an I/O error occurs.

Note:

The value may be negative indicating the number of milliseconds before the epoch.

Throws:

SecurityException - If a security manager exists and its java.lang.SecurityManager.checkRead(java.lang.String)method denies read access to the file.

Approach

Java

import java.io.File;

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

        String pathname = "D:\\hello.txt";
        File file = new File(pathname);

        System.out.println(file.lastModified());
    }
}

Output:

1661051935243


No comments:

Post a Comment