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?
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?
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
C:\
with attrib c:\
on my machine, and it said File C:\ not found
. (And yes, C:\
is my HD, so it exists.) –
Dalpe 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
D
, is also apparently hidden. However, if I insert a USB drive it is not hidden. I thought maybe the difference was that C
and D
had the "System" attribute (and this answer seemed to indicate the System attribute had similarities to the Hidden attribute) while my USB drive did not, but other system folders/files are also not hidden. –
Liquidation © 2022 - 2024 — McMap. All rights reserved.