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 ...
Get Java™ Phrasebook now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.