在Java中使用jimfs设置文件最后修改的时间戳

在Java中使用jimfs设置文件最后修改的时间戳,java,file,io,jimfs,Java,File,Io,Jimfs,如何使用jimfs设置文件的最后修改日期? 我有smth。像这样: final FileSystem fileSystem = Jimfs.newFileSystem(Configuration.unix()); Path rootPath = Files.createDirectories(fileSystem.getPath("root/path/to/directory")); Path filePath = rootPath.resolve("test1.pdf"); Path anot

如何使用jimfs设置文件的最后修改日期? 我有smth。像这样:

final FileSystem fileSystem = Jimfs.newFileSystem(Configuration.unix());
Path rootPath = Files.createDirectories(fileSystem.getPath("root/path/to/directory"));
Path filePath = rootPath.resolve("test1.pdf");
Path anotherFilePath = rootPath.resolve("test2.pdf");
创建完这些内容后,我创建了一个目录迭代器,如:

try (final DirectoryStream<Path> dirStream = Files.newDirectoryStream(rootPath, "*.pdf")) {
 final Iterator<Path> pathIterator = dirStream.iterator();
}
但是该方法返回
false

UDPATE


我刚刚看到文件#getLastModified()使用默认文件系统。这意味着将使用默认的本地文件系统来读取时间戳。这意味着我无法使用Jimfs创建临时文件,读取上次修改的文件,然后断言这些文件的路径。一个将具有jimfs://as uri方案,另一个将具有依赖操作系统的方案。

jimfs使用Java 7文件API。它实际上并不与旧的
文件
API混合,因为
文件
对象总是绑定到默认的文件系统。所以不要使用
文件

如果您有一个
路径
,那么您应该使用
java.nio.file.Files
类对其执行大多数操作。在这种情况下,您只需要使用

Files.setLastModifiedTime(path, FileTime.fromMillis(millis));

我是这方面的新手,但如果你选择一个特定的文件夹,并且你想从中提取最后一个文件,这是我的观点

     public static void main(String args[])  {
    //choose a FOLDER
    File  folderX = new File("/home/andy/Downloads");
    //extract all de files from that FOLDER
    File[] all_files_from_folderX = folderX.listFiles();
    System.out.println("all_files_from_folderXDirectories = " + 
                         Arrays.toString(all_files_from_folderX));
//we gonna need a new file
File a_simple_new_file = new File("");
// set to 0L (1JAN1970)
a_simple_new_file.setLastModified(0L);
 //check 1 by 1 if is bigger or no
for (File temp : all_files_from_folderX) {
if (temp.lastModified() > a_simple_new_file.lastModified())  {
            a_simple_new_file = temp; 
        }
//at the end the newest will be printed
System.out.println("a_simple_new_file = "+a_simple_new_file.getPath());
}
}}            

非常感谢,它就像一个符咒。现在我又能使用jimfs了。你救了我!!!
Files.setLastModifiedTime(path, FileTime.fromMillis(millis));
     public static void main(String args[])  {
    //choose a FOLDER
    File  folderX = new File("/home/andy/Downloads");
    //extract all de files from that FOLDER
    File[] all_files_from_folderX = folderX.listFiles();
    System.out.println("all_files_from_folderXDirectories = " + 
                         Arrays.toString(all_files_from_folderX));
//we gonna need a new file
File a_simple_new_file = new File("");
// set to 0L (1JAN1970)
a_simple_new_file.setLastModified(0L);
 //check 1 by 1 if is bigger or no
for (File temp : all_files_from_folderX) {
if (temp.lastModified() > a_simple_new_file.lastModified())  {
            a_simple_new_file = temp; 
        }
//at the end the newest will be printed
System.out.println("a_simple_new_file = "+a_simple_new_file.getPath());
}
}}