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?
Java 18 is the latest JDK development kit for Windows, Linux, and macOS platforms. If you are a beginner and looking for regular updates for a prolonged period, we recommend going with Java SE 11.
Downloading the JDK InstallerAccess Java SE Downloads page and click Accept License Agreement. Under the Download menu, click the Download link that corresponds to the .exe for your version of Windows. Download the file jdk-12. interim.
For Windows, choose to download Windows x64 Installer. Then you will download the jdk-13.0.2_windows-x64_bin.exe file (~160 MB), and verify SHA256 checksum for the downloaded file using this command: Run the Oracle JDK 13 installer program and you will see the following screen: The setup for Oracle JDK 13 is simple, quick and easy.
Download and Install OpenJDK 13 OpenJDK 13 is a reference implementation of Java SE 13 which was officially release on September, 17 th 2019. OpenJDK is free for personal, development and commercial use under GNU General Public License (GPLv2) without technical support.
The JDK is a development environment for building applications using the Java programming language. The JDK includes tools useful for developing and testing programs written in the Java programming language and running on the Java TM platform.
For Windows, you will download the file openjdk-13+33_windows-x64_bin.zip. (~186 MB). You should verify integrity of the downloaded file by comparing SHA256 checksum of the zip file with the one published on the website. On Windows, run this command:
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
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With