来自地狱的幻影文件夹(旧 Vista 安装)导致 Java String.equals() 问题

发布于 2024-09-06 11:57:04 字数 419 浏览 1 评论 0原文

我正在编写一个搜索计算机目录的程序。在我自己的计算机上,我安装了一个以前引导 Windows Vista 的驱动器。

(但是,有些驱动器即使“显示隐藏文件夹”也不会出现。 我可以看到运行 cmd 的文件夹,但这并不能解决我的问题。)

我不太关心文件夹,但我确实关心与它们的名称进行字符串比较。但是,当我使用 File Directory.getName() 获取这些虚拟文件夹的名称时, string.equals() 和 string.compareTo() 不适用于这些文件夹。

我已经打印了名称,检查了空格,使用了修剪等,但名为“Boot”的隐藏文件夹仍然与具有相同值的字符串不匹配。

TLDR:幻像目录使用 File Directory.getName() 返回无法匹配/可比较的字符串。

除了解决问题之外,我只是想知道发生了什么。

I'm writing a program that searches directories of a computer. On my own computer I have a drive installed which previously booted Windows Vista.

(However, there are drives that do not appear even when "show hidden folders".
I can see the folders running cmd, but that doesn't solve my problem.)

I don't care so much about the folders, but I do care about doing string comparisons with their names. However string.equals() and string.compareTo() does not work with these phantom folders when I get their name with File directory.getName().

I've printed out the names, checked for whitespace, used trim, etc. but a hidden folder named "Boot" will still not match with a string with same value.

TLDR: phantom directories return an unmatchable/comparable string with File directory.getName().

Besides solving the problem, I'm just curious to know what's going on.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

向地狱狂奔 2024-09-13 11:57:04

您的名称中可能包含隐藏字符。检查Boot文件夹的字符串长度是否为4。将字符串转换为字符数组并检查调试器中的每个单元格。

You may be getting hidden characters in the name. Check the string length of the Boot folder to see if it is four. Convert the String into an array of characters and examine each cell in a debugger.

第几種人 2024-09-13 11:57:04

比较文件名时使用不变比较。

Use Invariant comparisons when comparing filenames.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文