항상이 "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을 배치하여 실제로 파일을 찾았습니다. 그러나 그것을 올바르게 되돌려주지 않습니다. printline 코드 :
-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;
}
이는 printlines와 콘솔 반환 것입니다. 나는 이제 더 이상 모른다.
주요 문제는 재귀입니다. 무엇을 반환하고 싶습니까? 파일 경로? 또는 그것을 포함하는 디렉토리? –
파일 자체를 반환하고 싶습니다. 그러나 그것은 어떤 폴더에 묻혀있다. 그래서 이것을 사용하여 그것을 찾습니다. – mrjvs