我有一个带双精度列表的文本文件。该行的第一个值是x值,第二个值是y值。将双精度加载到arrayList中
103.0 274.0
133.0 383.0
342.0 250.0
204.0 126.0
177.0 357.0
...
如何读取这些值并将它们加载到数组列表中?
ArrayList<Point> store = new ArrayList<Point>();
File file = fc.getSelectedFile();
StringBuilder all = new StringBuilder();
BufferedReader reader = new BufferedReader(new FileReader(file));
String input = null;
while ((input = reader.readLine()) != null)
{
String a = all.append(input+"\n").toString();
String[] hold = a.split(" ");
double x = Double.parseDouble(hold[0]);
int aa = (int)(x);
double y = Double.parseDouble(hold[1]);
int bb = (int)(y);
store.add(new Point(aa, bb));
}
http://stackoverflow.com/questions/1855753/reading-文件双值 – 2012-03-19 05:09:43
格式化您的代码时请多加小心(本论坛无法顺利处理标签,特别是在与空间混合使用时不能正常处理 - 如您所见:-) – kleopatra 2012-03-19 11:22:26