大家好,我在以下路径 C:/Users/Marc/Downloads/vector25 中有一个文本文件,其中包含以下格式的逗号分隔值
-6.08,70.93,-9.35,-86.09,-28.41,27.94,75.15,91.03,-84.21,97.84,-51.53,77.95,88.37,26.14,-23.58,-18.4,-4.62,46.52,-19.47,17.54, 85.33,52.53,27.97,10.73,-5.82,
我将如何阅读这个文本文件并将这些双精度数存储在一个数组中?
我目前正在考虑尝试使用缓冲阅读器,但到目前为止,我无法找到答案,谁能指出我正确的方向?
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Scanner;
public class subvector {
public static void main(String[] args){
FileReader file = null;
try {
file = new FileReader("C:/Users/Marc/Downloads/vector25");
} catch (FileNotFoundException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
ArrayList<Double> list = new ArrayList<Double>();
int i=0;
try {
Scanner input = new Scanner(file);
while(input.hasNext())
{
list.add(input.nextDouble());
i++;
}
input.close();
}
catch(Exception e)
{
e.printStackTrace();
}
for(double k:list){
System.out.println(k);
}
}