I wish to change the timestamp metadata on files in Java using the java.nio.Files class.
I would like to change all 3 Linux/ext4 timestamps (last modifi
Adapting this answer to your case:
// Warning: Disk must be unmounted before this operation
String disk = "/dev/sda1";
// Update ctime
Runtime.getRuntime().exec("debugfs -w -R 'set_inode_field "+pathToMyFile+" ctime "+myCustomTime+"' "+disk);
// Drop vm cache so ctime update is reflected
Runtime.getRuntime().exec("echo 2 > /proc/sys/vm/drop_caches");
I doubt we will see a convenient method in Standard Java API to do this, as neither Linux (man touch) nor Windows (GetFileTime function on MSDN) give easy access to this field. Native system calls give only access to creation/access/modify timestamps, so does Java.