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 GMT). Both of these methods will return a boolean value of true only if the operation is successful. If the operation fails for any reason, a value of false will be returned.




JavaT Phrasebook. Essential Code and Commands
Java Phrasebook
ISBN: 0672329077
EAN: 2147483647
Year: 2004
Pages: 166

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net