How to set the last modified date time of a directory 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://tmp");

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

            lastModified = new Date();

            boolean b = file.setLastModified(lastModified.getTime());

            if (b)
                System.out.println(new Date(file.lastModified()));
            else
                System.out.println("last modified time not set");

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

/*
           
run:
     
Wed Nov 16 09:21:44 IST 2016
Sat Nov 19 22:15:54 IST 2016
  
 */

 



answered Nov 19, 2016 by avibootz

Related questions

1 answer 165 views
1 answer 196 views
1 answer 192 views
1 answer 131 views
1 answer 136 views
...