我在尝试从 txt 文件加载某些数据时遇到此错误。
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/ 分裂有关吗?
谢谢
这是工作的:
sque = 1923 3208 3214 1 0 2 Square
但是,我正在尝试加载其中的 400 多个,并且一次更改所有这些会很痛苦