O'Reilly logo

Java™ Phrasebook by Timothy Fisher

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Changing File Attributes

File f = new File("somefile.txt");
											boolean result = f.setReadOnly();
											long time = (new Date()).getTime();
											result = f.setLastModified(time);

The File object makes it easy to change the last modified time stamp on a file and the read/write status of a file. To perform these tasks, we use the setReadOnly() and setLastModified() methods of the File class. The setReadOnly() method, as you have probably guessed, sets the read/write status of the file on which the method is called to read-only. The setLastModified() method accepts a single parameter, specifying a time in milliseconds, and sets the file’s last modified time to that time. The time value passed in is measured in milliseconds since the epoch (January 1, 1970, 00:00:00 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required