Windows上的JDK12和JDK13之间更改了Files.isHidden C:\\ [英] Files.isHidden C:\\ changed between JDK12 and JDK13 on windows

查看:118
本文介绍了Windows上的JDK12和JDK13之间更改了Files.isHidden C:\\的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Files.isHidden(Path.of("c:\\"))在Windows 10,JDK 13上返回true

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

但是在同一台JDK 12计算机上返回false.

but returns false on JDK 12 same machine.

有人知道这是为什么吗?

Anyone know why this is?

推荐答案

如前所述,行为上的差异是由于修复了一个错误而引起的:

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.

在对该问题的评论中指出,结果也与java.io.File#isHidden()不一致.实际上,如果您使用:

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());

即使在Java 12和更早的版本中(至少在Windows 10 Home计算机上也是如此),您会看到true打印出来.

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

C:\被报告为隐藏的事实似乎对我来说是正确的.如果我在 PowerShell 中检查C:\的属性,它会将目录显示为隐藏.

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

这篇关于Windows上的JDK12和JDK13之间更改了Files.isHidden C:\\的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆