Touch a file: set File Last Modified Time
The following code set the last modified time to current time.
import java.io.File;
import java.util.Date;
class Touch {
public static void main(String[] args) {
String[] names = new File(".").list();
Date current = new Date();
for (int i = 0; i < names.length; i++) {
File f = new File(names[i]);
f.setLastModified(current.getTime());
}
}
}
Home
Java Book
Runnable examples
Java Book
Runnable examples
IO File:
- Compare File Dates
- Compress files using with ZIP
- Concatenate files
- Copy a File with NIO FileChannel and ByteBuffer
- Copy a file with FileReader and FileWriter
- Copy a file with InputStream and OutputStream
- Copy a file and overwrite
- Delete a file
- Delete File Recursively
- Get readable file size
- Move a file
- Rename a file
- Report a file's status
- Search a file by regular expressions
- Touch a file: set File Last Modified Time