我試圖從txt文件加載某些數據時出現此錯誤。嘗試加載文件時出現java.lang.NumberFormatException
public static boolean initalize(String FileName) {
String line = "";
String token = "";
String token2 = "";
String token2_2 = "";
String[] token3 = new String[10];
boolean EndOfFile = false;
BufferedReader characterfile = null;
try {
characterfile = new BufferedReader(new FileReader("./Data/data/"
+ FileName));
} catch (FileNotFoundException fileex) {
Misc.println("File not loaded");
return false;
}
try {
line = characterfile.readLine();
} catch (IOException ioexception) {
return false;
}
while ((EndOfFile == false) && (line != null)) {
**line = line.trim();
int spot = line.indexOf("=");
if (spot > -1) {
token = line.substring(0, spot);
token = token.trim();
token2 = line.substring(spot + 1);
token2 = token2.trim();
token2_2 = token2.replaceAll("\t\t", "\t");
token2_2 = token2_2.replaceAll("\t\t", "\t");
token2_2 = token2_2.replaceAll("\t\t", "\t");
token2_2 = token2_2.replaceAll("\t\t", "\t");
token2_2 = token2_2.replaceAll("\t\t", "\t");
token3 = token2_2.split("\t");**
if (token.equals("drop")) {
int id = Integer.parseInt(token3[0]);
int x = Integer.parseInt(token3[1]);
int y = Integer.parseInt(token3[2]);
int amount = Integer.parseInt(token3[3]);
int height = Integer.parseInt(token3[4]);
globalDrops.add(new GlobalDrop(id,amount,x,y,height));
}
} else {
if (line.equals("[ENDOFDROPLIST]")) {
try {
characterfile.close();
} catch (IOException ioexception) {
}
return true;
}
}
try {
line = characterfile.readLine();
} catch (IOException ioexception1) {
EndOfFile = true;
}
}
try {
characterfile.close();
} catch (IOException ioexception) {
}
return false;
}
然而,它一直給我這個錯誤:
[8/3/12 5:24 PM]: Exception in thread "main" [8/3/12 5:24 PM]: java.lang.NumberFormatException: For input string: "1923 3208 3214 1 0 2 "
這是文本文件是如何被格式化:
sque = 1923 3208 3214 1 0 2 Square
這是爲什麼給我這個錯誤?這是否與/ t/split有關?
感謝
這是一個工作:
sque = 1923 3208 3214 1 0 2 Square
不過,我試圖加載在這些400,這將是痛苦的改變所有這些一次
您粘貼的版本以空格分隔。 – Wug 2012-08-03 21:32:42