How to get the last modified date time of a file in Java

1 Answer

0 votes
package javaapplication1;

import java.io.File;
import java.io.IOException;
import java.util.Date;

public class JavaApplication1 {

    public static void main(String[] args) throws IOException {

        try {

            File file = new File("d://data.txt");

            Date lastModified = new Date(file.lastModified());
            System.out.println(lastModified);

        } catch (Exception e) {
            System.out.print(e.toString());
        }
    }
}

/*
           
run:
     
Tue Nov 15 12:51:29 IST 2016
  
 */

 



answered Nov 19, 2016 by avibootz

Related questions

1 answer 197 views
1 answer 166 views
1 answer 131 views
1 answer 136 views
1 answer 189 views
...