来自地狱的幻影文件夹(旧 Vista 安装)导致 Java String.equals() 问题
我正在编写一个搜索计算机目录的程序。在我自己的计算机上,我安装了一个以前引导 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您的名称中可能包含隐藏字符。检查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.
比较文件名时使用不变比较。
Use Invariant comparisons when comparing filenames.