常にそれが「level.dat」と呼ばれる特定のファイルのディレクトリを検索し、以下のこのメソッドはnullを返します:ディレクトリ検索メソッドは常にnullを返します
File leveldat = traverse(wftemp,"level.dat");
:
private static File traverse(File dir, String name) {
if (dir.isDirectory()) {
String[] children = dir.list();
for (int i = 0; children != null && i < children.length; i++) {
traverse(new File(dir, children[i]),name.trim());
}
}
if (dir.isFile()) {
if (dir.getName().trim().equalsIgnoreCase(name.trim())) {
return dir;
}
}
return null;
}
は、メソッドは、この使用して呼び出されます
wftempはディレクトリへのパスです。
いくつかのprintlnを置くことによって、実際にファイルが見つかることがわかりました。それを正しく返すことはありません。 プリントラインコード:
-snip-
C:\Users\mrjvs\AppData\Roaming\the stanley parable\temp\stanleyparablemoesh\The stanley parable for moesh\DIM1\##MCEDIT.TEMP##
C:\Users\mrjvs\AppData\Roaming\the stanley parable\temp\stanleyparablemoesh\The stanley parable for moesh\DIM1\##MCEDIT.TEMP2##
C:\Users\mrjvs\AppData\Roaming\the stanley parable\temp\stanleyparablemoesh\The stanley parable for moesh\DIM1\playerdata
C:\Users\mrjvs\AppData\Roaming\the stanley parable\temp\stanleyparablemoesh\The stanley parable for moesh\icon.png
C:\Users\mrjvs\AppData\Roaming\the stanley parable\temp\stanleyparablemoesh\The stanley parable for moesh\level.dat
We found a match: C:\Users\mrjvs\AppData\Roaming\the stanley parable\temp\stanleyparablemoesh\The stanley parable for moesh\level.dat
C:\Users\mrjvs\AppData\Roaming\the stanley parable\temp\stanleyparablemoesh\The stanley parable for moesh\level.dat_old
C:\Users\mrjvs\AppData\Roaming\the stanley parable\temp\stanleyparablemoesh\The stanley parable for moesh\mcedit_waypoints.dat
C:\Users\mrjvs\AppData\Roaming\the stanley parable\temp\stanleyparablemoesh\The stanley parable for moesh\playerdata
C:\Users\mrjvs\AppData\Roaming\the stanley parable\temp\stanleyparablemoesh\The stanley parable for moesh\playerdata\4e879a3b-c247-4d9a-8ec8-577172a00356.dat
C:\Users\mrjvs\AppData\Roaming\the stanley parable\temp\stanleyparablemoesh\The stanley parable for moesh\region
C:\Users\mrjvs\AppData\Roaming\the stanley parable\temp\stanleyparablemoesh\The stanley parable for moesh\region\r.-1.-1.mca
-snip-
私は1.5時間以上しようとしている:
private static File traverse(File dir, String name) {
System.out.println(dir.getAbsolutePath());
if (dir.isDirectory()) {
String[] children = dir.list();
for (int i = 0; children != null && i < children.length; i++) {
traverse(new File(dir, children[i]),name.trim());
}
}
if (dir.isFile()) {
if (ddir.getName().trim().equalsIgnoreCase(name.trim())) {
System.out.println("We found a match: " + dir.getAbsolutePath());
return dir;
}
}
return null;
}
これは、コンソールがプリントラインで返すものです。私はもう知らない。
あなたの主な問題は再帰性です。あなたは何を返そうとしていますか?ファイルのパス?またはそれを含むディレクトリ? –
ファイル自体を返すようにします。それはいくつかのフォルダに埋もれています。私はそれを見つけるためにこれを使います。 – mrjvs