1
を2倍に文字列を変換:読むCSVと私は、Javaに新しいですし、私がオープンCSVを使用してCSVファイルを読んでいますし、私のコードは以下の通りです
import java.io.FileReader;
import java.util.Arrays;
import au.com.bytecode.opencsv.CSVReader;
public class ParseCSVLineByLine
{
double arr []=new arr[10];
public static void main(String[] args) throws Exception
{
//Build reader instance
//Read data.csv
//Default seperator is comma
//Default quote character is double quote
//Start reading from line number 2 (line numbers start from zero)
CSVReader reader = new CSVReader(new FileReader("data.csv"), ',' , '"' , 1);
//Read CSV line by line and use the string array as you want
String[] nextLine;
int i=0;
while ((nextLine = reader.readNext()) != null) {
if (nextLine != null && i<10) {
//Verifying the read data here
arr[i]=Double.parseDouble(Arrays.toString(nextLine).toString());
System.out.println(arr[i]);
}
i++;
}
}
}
しかし、私は唯一の
を印刷するとき、これはworks.ButていませんArrays.toString(nextLine).toString()
これは、私は変換がproblem.Anyヘルプは高く評価されたと思う
[1]
[2]
[3]
.
.
.
.
[10]
を印刷します。
csvファイルには何が入力されていますか? –
'Arrays.toString(nextLine)'は、おそらく1つだけの要素でもあなたが投稿した文字列、つまり '' [1] ''を得るので、doubleとして解析できないものになります。なぜDouble.parseDouble(nextLine [index]) '' index'はおそらく0ではないのでしょうか? – Thomas
受け入れてくれてありがとう、私は私の答えが役立ってうれしいです – GhostCat