简体   繁体   English

将文本文件插入二维数组

[英]Inserting a text file into 2d array

I want to read a text file and insert it into 2d double array. 我想读取一个文本文件并将其插入2d双数组。 I have this code, but the first problem is that it doest not read the last column and the second problem is that it returns just the first line of my text file. 我有这段代码,但是第一个问题是它不读取最后一列,第二个问题是它仅返回了我的文本文件的第一行。 For example, if the text file is 例如,如果文本文件是

1.1,2.1,3.1
2.1,1.1,4.1
1.3,3.2,5.1

It returns: 它返回:

{1.1 2.1}

How should I fix it? 我应该如何解决?

BufferedReader match_dataset = new BufferedReader(new FileReader("test.txt"));
Scanner src = new Scanner(match_dataset);
ArrayList<Double> lines = new ArrayList<Double>();
src.useDelimiter(",");

while (src.hasNextDouble()) {
    lines.add(src.nextDouble());
}
Double[] temp_match = new Double[lines.size()];
lines.toArray(temp_match);

You have the wrong syntax for a double array. 双数组的语法错误。 Should be two brackets [][] after double 双括号后应为两个括号[] []

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM