【发布时间】:2018-02-05 15:14:06
【问题描述】:
我有这段代码可以将数字(双精度类型)从文本文件读取到列表中。
ArrayList listTest = new ArrayList();
try {
FileInputStream fis = new FileInputStream(path);
InputStreamReader isr = new InputStreamReader(fis, "UTF-16");
int c;
while ((c = isr.read()) != -1) {
listTest.add((char) c);
}
System.out.println();
isr.close();
} catch (IOException e) {
System.out.println("There is IOException!");
}
但是,输出看起来像:
1
1
.
1
4
7
4
2
.
8
1
7
3
5
而不是
11.147
42.81735
如何将数字逐行添加到列表中?
【问题讨论】: