我试图从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