I want to change modification timestamp of a binary file. What is the best way for doing this?
Would opening and closing the file be a good option? (I require a solution
Since File
is a bad abstraction, it is better to use Files
and Path
:
public static void touch(final Path path) throws IOException {
Objects.requireNotNull(path, "path is null");
if (Files.exists(path)) {
Files.setLastModifiedTime(path, FileTime.from(Instant.now()));
} else {
Files.createFile(path);
}
}