4

私は Windows 8 を
使用しています 。Javadoc forFile#list()は、「この抽象パス名がディレクトリを示さない場合、または I/O エラーが発生した場合は null を返します」と主張しています。

ここで、「ディレクトリ」(実際には NTFS ジャンクション) の「アプリケーション データ」(C:\Users\[Username] ディレクトリにあります) の例を見てみましょう。

File#isDirectory()「Application Data」を呼び出すと、 が返されますtrue。ただし、「Application Data」を呼び出すとFile#list()、毎回 null が返されるため、I/O エラーではありません。

基本的に、これは役に立たない呼び出しを行い、が実際にディレクトリであることを確認したいかどうかFile#isDirectory()を確認することを強制します。File#list() != nullFile

私が間違っていない限り、ファイルが実際にディレクトリであるかどうかを「確実に」確認する方法は他にありませんか? File#list()ファイルシステム上のすべてのフォルダーで実行している場合、非常に高価なメソッド呼び出しです。

この問題を例示する Java ファイルは次のとおりです。 http://pastebin.com/ieH0xTek Windows でのみ動作します。

4

1 に答える 1

2

Hidden system junctions (such as Local Settings or Application Data) are special:

These junction points have file attributes of FILE_ATTRIBUTE_REPARSE_POINT and FILE_ATTRIBUTE_SYSTEM, and the access control lists (ACLs) must be set to "“Everyone Deny Read". Applications must have permissions in order to call out and traverse a specific path. However, enumerating the contents of these junction points is not possible.

This means that they can not be traversed in a standard manner (due to the security settings). Unfortunately there is no way to work with these junctions through the old Java File API.

With Java 7's NIO.2 file system API it should be possible to detect these links and probably resolve their target path.

于 2013-10-13T13:15:02.987 に答える