Reputation: 127
On my windows 10 machine when I check for hidden folders, Files.isHidden always returns false.
C:\ProgramData is generally a hidden folder but the program returns false instead of expected true
public static void main(String[] args) throws IOException {
Path directory = Path.of("C:\\ProgramData").toAbsolutePath().normalize();
System.out.println(Files.isHidden(directory));
}
Upvotes: 1
Views: 58
Reputation: 1340
You have probably hit a bug. JDK 13 has been patched with a fix. Use the recommendations in the fix note
eg.
public static void main(String[] args) throws IOException {
Path directory = Path.of("C:\\ProgramData").toAbsolutePath().normalize();
DosFileAttributes dosFileAttributes = Files.readAttributes(directory, DosFileAttributes.class);
System.out.println(Files.isHidden(directory)); // Returns true for > JDK13
System.out.println(dosFileAttributes.isHidden()); // Returns true for < JDK13
}
Upvotes: 4