简体   繁体   English

java File.listFiles()不返回链接

[英]java File.listFiles() doesn't return links

I'm trying to use listFiles() method on a file pointing to my desktop folder to read every file on my desktop. 我试图在指向桌面文件夹的文件上使用listFiles()方法来读取桌面上的每个文件。

The strange thing is that the method reads some links (.lnk) but can't find some others (ok it can't find the bin icon, but also can't find some others links referencing to some non-windows programs). 奇怪的是,该方法读取某些链接(.lnk),但是找不到其他链接(好吧,它找不到bin图标,但也找不到引用某些非Windows程序的其他链接)。 The same thing happens if I use the command DIR on windows cmd. 如果在Windows cmd上使用命令DIR,也会发生相同的情况。

How can I resolve this? 我该如何解决? Thank you very much! 非常感谢你!

It may be that the files you try and list do not show because they are marked as hidden. 您尝试列出的文件可能没有显示,因为它们被标记为隐藏。

In order to verify that, try this: 为了验证,请尝试此:

final Path path = Paths.get("path/to/desktop.ini");
System.out.println(Files.getAttribute(path, "dos:hidden"));

Also, try and use this to see whether those files show up: 另外,尝试并使用它来查看这些文件是否显示:

final Path dir = Paths.get("path/to/desktop/folder");
for (final Path entry: Files.newDirectoryStream(dir))
    System.out.println(entry);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM