Files.isHidden C:\\ changed between JDK12 and JDK13 on windows

隐身守侯 提交于 2020-05-27 03:58:58

问题


Files.isHidden(Path.of("c:\\")) returns true on Windows 10, JDK 13

but returns false on JDK 12 same machine.

Anyone know why this is?


回答1:


It was a bug that was fixed with JDK 13.

On Microsoft Windows, the java.nio.file.Files.isHidden method has historically ignored the DOS "hidden" attribute on directories. This has been fixed in this release so that isHidden now returns true when invoked to test a directory that has this attribute set.

From the release notes




回答2:


As already mentioned, the difference in behavior is due to a bug being fixed: JDK-8215467. The description of the bug explains that, before the fix, the result of Files#isHidden(Path) was inconsistent with other core software on Windows (e.g. File Explorer, PowerShell, CMD, etc.). The inconsistency was that directories in Windows certainly can be hidden but Java (or at least NIO2) thought otherwise.

In the comments to the issue it was pointed out the result was also inconsistent with java.io.File#isHidden(). In fact, if you use:

File file = new File("C:\\");
System.out.println(file.isHidden());

You'll see true printed out, even in Java 12 and older (at least I do on my Windows 10 Home machine).

The fact C:\ is being reported as hidden appears to be correct for me. If I check the attributes of C:\ in PowerShell it shows the directory as hidden.

PS C:\> $root = Get-Item "C:\"
PS C:\> $root.Attributes
Hidden, System, Directory


来源:https://stackoverflow.com/questions/58169000/files-ishidden-c-changed-between-jdk12-and-jdk13-on-windows

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!