Files.setLastModifiedTime doesn't work
Michael Hall
mik3hall at gmail.com
Sun May 22 15:56:45 PDT 2011
I just posted on this to the nio.2 discuss list but I don't always seem to get through there. Maybe sending from a mail account other than the one I subscribed on.
Anyhow I can't seem to get Files.setLastModifiedTime to work.
The code
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.attribute.FileTime;
public class TestTime {
public static void main(String[] args) {
// File filefsp = new File(System.getProperty("user.dir"),"basic");
Path filefspPath = Paths.get(System.getProperty("user.dir"),"basic");
System.out.println("path is " + filefspPath);
FileTime ft = FileTime.fromMillis(System.currentTimeMillis());
try {
Files.setLastModifiedTime(filefspPath,ft);
}
catch (IOException ioex) { ioex.printStackTrace(); }
// System.out.println(filefsp.setLastModified(System.currentTimeMillis()));
}
}
The File.setLastModified in the last println did work.
Originally I was testing with a directory but the current version is with a text file. Neither worked.
The javadoc example is...
Path path = ...
FileTime now = FileTime.fromMillis(System.currentTimeMillis());
Files.setLastModifiedTime(path, now);
I'm not that far from it. But I suppose I could still be doing something not quite right?
More information about the macosx-port-dev
mailing list