Java bug或windows bug文件创建时间

时间:2015-03-26 11:39:50

标签: java file file-io filesystems nio

删除文件并重新创建时,“创建时间:”始终与首次创建时相同。

Path path = Paths.get(file);
BasicFileAttributes attr = Files.readAttributes(path , BasicFileAttributes.class);
System.out.println("Creation time: " + attr.creationTime())

添加完整源代码:

public class FileCreationTimeTest {

    @Test
    public void testFileTimeCreation() throws Exception {
        for(int i = 0; i < 10; i++) {
            FileTime fileTime = getFileCreationTime();
            System.out.println(fileTime);
            Thread.sleep(1000);
            FileTime fileTime2 = getFileCreationTime();
            System.out.println(fileTime2);
            Assert.assertEquals(fileTime.compareTo(fileTime2), 0);
        }
    }

    private FileTime getFileCreationTime() throws Exception {
        File file = new File("test.txt");
        file.createNewFile();
        Path path = Paths.get(file.getAbsolutePath());
        BasicFileAttributes attr = Files.readAttributes(path , BasicFileAttributes.class);
        FileTime fileTime = attr.creationTime();
        file.delete();
        return fileTime;
    }
 }

环境:Windows 7,JRE 1.8.0_25

这个错误吗?

0 个答案:

没有答案