그래서 폴더의 모든 파일을 읽고 파일에서 읽은 변수가있는 목록에 새 클래스를 만드는 메서드가 있습니다. 웬일인지 경로가 정확하고 두 번 폴더가 있는지 확인 했는데도 if(mainDir.isDirectory()){
부분을 지나치지 않습니다.디렉터리가 인식되지 않습니다
public static void loadIntoClass(String dir, int temp){
try {
File mainDir = new File(dir);
if(mainDir.isDirectory()){ //Checks if the dir is a folder and not a file
String[] fileNames = mainDir.list(); //Grabs a list of all the filenames in the dir
for(int x = 0; x > fileNames.length; x++){ //loops through all the files
File currFile = new File(dir + fileNames[x]); //Creates the object we will be gathering information from
if(currFile.isFile()){ //Checks to make sure the file is a file and not a folder
BufferedReader br = new BufferedReader(new FileReader(currFile));
String line = br.readLine();
int currLoop = 1;
boolean collides = false;
while(line != null){ //Will keep checking files until it reaches a blank line
currLoop ++; //Keeps track of how many times it loops
test = line.split("="); //Splits up the variable from the declaration
String toString = test[0].trim(); //Trims off any extra blank spaces on either side
System.out.println("Reading: " + toString + " on line " + currLoop); //For debugging
String toString2 = test[1].trim(); //Trims the second string
parse[currLoop] = Integer.parseInt(toString2); //Turns the string into an integer then puts it into the array
if(toString.equalsIgnoreCase("Collides")){
if(toString2.equalsIgnoreCase("true")){
collides = true;
}
}
if(toString.equalsIgnoreCase("Image Path")){
//path = toString2;
}
line = br.readLine();
}
if(temp == 1){
types.add(new Type(parse[1], parse[2], parse[3], parse[4], parse[5], parse[6], parse[7]));
}
if(temp == 2){
tiles.add(new Tiles(parse[1], collides, null));
}
if(temp == 3){
abilities.add(new Abilities(parse[1], parse[2], parse[3], parse[4]));
}
br.close();
}
}
}
} catch(Exception e) {
System.err.println("ERROR: " + e);
}
}
그런 다음 "C :/test"와 같은 다른 경로를 변경하면 for 루프에서만 고정됩니다.
당신이 코드의 THH 휴식을 게시 할 수있는 경우는 고원 도움이 될. – dharam
나는'File currFile = new File (dir + fileNames [x])'에 대해 걱정할 것이다. 이것은 C :/Program Files (x86) /GameNameHere/config/enemiessomefilename.ext " 당신이 원하는. 대신 단순히'mainDir.listFiles()'를 사용하면'File'의 배열을 반환 할 것입니다. – MadProgrammer
디렉토리의 이름을 바꿨습니까? Windows에서는 일반적으로'C : \ Program Files (x86)'이 아니라'C : \ Program Files (x86)'이라고 불립니다. – Jesper