This example demonstrates 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 does not exist, a new file will be
// created. If the file exists, change the file timestamp.
FileUtils.touch(file);
} catch (IOException e) {
e.printStackTrace();
}
}
}
Maven Dependencies
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.14.0</version>
</dependency>
Latest posts by Wayan (see all)
- How do I get number of each day for a certain month in Java? - September 8, 2024
- How do I get operating system process information using ProcessHandle? - July 22, 2024
- How do I sum a BigDecimal property of a list of objects using Java Stream API? - July 22, 2024