This example demonstrate a touch
command just like Unix touch command. If the file to be touched doesn’t exist a new empty file will be created.
package org.kodejava.commons.io;
import org.apache.commons.io.FileUtils;
import java.io.File;
import java.io.IOException;
public class TouchFileExample {
public static void main(String[] args) {
try {
File file = new File("Touch.dat");
// Touch the file, when the file is not exist a new file will be
// created. If the file exist change the file timestamp.
FileUtils.touch(file);
} catch (IOException e) {
e.printStackTrace();
}
}
}
Maven Dependencies
<!-- https://search.maven.org/remotecontent?filepath=commons-io/commons-io/2.11.0/commons-io-2.11.0.jar -->
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.11.0</version>
</dependency>
Latest posts by Wayan (see all)
- How do I convert Map to JSON and vice versa using Jackson? - June 12, 2022
- How do I find Java version? - March 21, 2022
- How do I convert CSV to JSON string using Jackson? - February 13, 2022