File lastModified() method in Java with Examples Last Updated : 28 Jan, 2019 Summarize Comments Improve Suggest changes Share Like Article Like Report The lastModified() function is a part of File class in Java . This function returns the time denoted by the this abstract pathname was last modified.The function returns long value measured in milliseconds, representing the time the file was last modified else returns 0L if the file does not exists or if an exception occurs. Function signature: public long lastModified() Syntax: long valr = file.lastModified(); Parameters: This method does not accept any parameter. Return TypeThis function returns long data type representing the time the file was last modified or 0L if the file does not exist. Exception: This method throws Security Exception if the write access to the file is denied Below programs illustrates the use of lastModified() function: Example 1: The file "F:\\program.txt" is a existing file in F: Directory. Java // Java program to demonstrate // lastModified() method of File Class import java.io.*; public class solution { public static void main(String args[]) { // Get the file File f = new File("F:\\program.txt"); // Get the last modified time of the file System.out.println("Last modified: " + f.lastModified()); } } Output: Last modified: 1542654265978 Example 2: The file "F:\\program1.txt" does not exist Java // Java program to demonstrate // lastModified() method of File Class import java.io.*; public class solution { public static void main(String args[]) { // Get the file File f = new File("F:\\program.txt"); // Get the last modified time of the file System.out.println("Last modified: " + f.lastModified()); } } Output: Last modified: 0 Note: The programs might not run in an online IDE. Please use an offline IDE and set the path of the file. Comment More infoAdvertise with us Next Article File lastModified() method in Java with Examples A andrew1234 Follow Improve Article Tags : Java Java-Functions Java-IO package Java-File Class Practice Tags : Java Similar Reads File length() method in Java with Examples The length() function is a part of File class in Java . This function returns the length of the file denoted by the this abstract pathname was length.The function returns long value which represents the number of bytes else returns 0L if the file does not exists or if an exception occurs. Function s 2 min read File setLastModified() method in Java with Examples The setLastModified() method is a part of File class.The function sets the last modified time of the file or directory. The function sets the last modified value of the file in milliseconds.Function Signature:Â Â public boolean setLastModified(long time) Function Syntax:Â Â file.setLastModified(time) 3 min read File renameTo() method in Java with examples The renameTo() method is a part of File class. The renameTo() function is used to rename the abstract path name of a File to a given path name. The function returns true if the file is renamed else returns false Function Signature: public boolean renameTo(File destination) Syntax: file.renameTo(File 2 min read Files copy() Method in Java with Examples The copy() method of java.nio.file.Files Class is used to copy bytes from a file to I/O streams or from I/O streams to a file. I/O Stream means an input source or output destination representing different types of sources e.g. disk files. Methods: Based on the type of arguments passed, the Files cla 5 min read Files size() method in Java with Examples size() method of java.nio.file.Files help us to get the size of a file (in bytes). This method returns the file size, in bytes by taking the path of the file as a parameter. The size may differ from the actual size on the file system due to compression, support for sparse files, or other reasons. Th 2 min read Like