Change Last Modified Date Timestamp of a File in Java using Commons FileUtils
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
import java.io.IOException; import org.apache.commons.io.FileUtils; import java.io.File; public class Main { public static void main(String[] args) { try { File file = new File("pic.jpg"); long lastModified1 = file.lastModified(); FileUtils.touch(file); long lastModified2 = file.lastModified(); System.out.println("File date / time was updated: " + (lastModified2 < lastModified1)); } catch (IOException ex) { ex.printStackTrace(); } } } |
Output:
File date / time was updated: true