我试图在两个数组列表中区分和存储文本文件中的数据(点:x,y):结和零。数据文件只包含整数或十进制值。
Data File:
x y type(zero/knot)
46 10 2
13 5 2
27 21 1
但我的代码抛出 NumberFormatException:48
import java.util.*;
import java.util.ArrayList;
import java.io.*;
import java.awt.Point;
public class program {
public static void main(String []args) {
ArrayList knots = new ArrayList<Point>();
ArrayList zeros = new ArrayList<Point>();
List<Integer> list = new ArrayList<Integer>();
String line = null;
String file = "data1.txt";
BufferedReader reader;
try {
reader = new BufferedReader(new FileReader(file));
while((line = reader.readLine()) != null) {
String tmp[] = line.split(" ");
System.out.println(line);
for (String s:tmp) {
s = s.replace("\r\n","");
int i = Integer.parseInt(s.trim());
//knots.add(new Point();
System.out.println(s);
}
}
}
catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}