How do I perform a touch on a file?
Author: Deron Eriksson
Description: This Java tutorial describes how to perform a touch on a file using Commons IO.
Tutorial created using: Windows XP || JDK 1.5.0_09 || Eclipse Web Tools Platform 2.0 (Eclipse 3.3.0)


Page: < 1 2

(Continued from page 1)

The Touch class first touches 'new-file.txt', which doesn't exist. This creates 'new-file.txt' and labels it with the current time as the last-modified time. The Touch class then touches 'test.txt', which already exists. It modifies the last-modified time of 'test.txt' to be the current time.

The console output of the Touch class is shown here:

Checking new-file.txt
new-file.txt does not exist
Modified: Wed Dec 31 16:00:00 PST 1969
Calling 'touch'
new-file.txt exists
Modified: Sat Jan 26 23:02:19 PST 2008

Checking test.txt
test.txt exists
Modified: Sat Jan 26 22:54:27 PST 2008
Calling 'touch'
test.txt exists
Modified: Sat Jan 26 23:02:19 PST 2008

Page: < 1 2