Here is a JNA example showing how Unix touch can be invoked through JNA to change the timestamps of an existing file. Try passing the novel Unix time of 1234567890. The code is HERE
import com.sun.jna.*;
import com.sun.jna.ptr.*;
public class Touch {
/** Definition of the C library. */
interface CLibrary extends Library {
CLibrary INSTANCE = (CLibrary)Native.loadLibrary("c", CLibrary.class);
public int utime(String filename, utimbuf buf);
}
public static class time_t extends Structure {
public int value;
public time_t() {}
public time_t(int value) {
this.value = value;
}
}
public static class utimbuf extends Structure {
public time_t actime;
public time_t modtime;
public utimbuf() {}
public utimbuf(time_t actime, time_t modtime) {
this.actime = actime;
this.modtime = modtime;
}
}
public static void main(String[] args) {
CLibrary lib = CLibrary.INSTANCE;
if (args.length < 2) {
System.out.println("Usage: java Touch <filename> <unix time in seconds>");
System.exit(1);
}
String filename = args[0];
time_t filetime = new time_t(Integer.valueOf(args[1]));
utimbuf buf = new utimbuf(filetime, filetime);
System.out.println(CLibrary.INSTANCE.utime(filename, buf));
}
}
import com.sun.jna.ptr.*;
public class Touch {
/** Definition of the C library. */
interface CLibrary extends Library {
CLibrary INSTANCE = (CLibrary)Native.loadLibrary("c", CLibrary.class);
public int utime(String filename, utimbuf buf);
}
public static class time_t extends Structure {
public int value;
public time_t() {}
public time_t(int value) {
this.value = value;
}
}
public static class utimbuf extends Structure {
public time_t actime;
public time_t modtime;
public utimbuf() {}
public utimbuf(time_t actime, time_t modtime) {
this.actime = actime;
this.modtime = modtime;
}
}
public static void main(String[] args) {
CLibrary lib = CLibrary.INSTANCE;
if (args.length < 2) {
System.out.println("Usage: java Touch <filename> <unix time in seconds>");
System.exit(1);
}
String filename = args[0];
time_t filetime = new time_t(Integer.valueOf(args[1]));
utimbuf buf = new utimbuf(filetime, filetime);
System.out.println(CLibrary.INSTANCE.utime(filename, buf));
}
}