次のコードがあります。.csv ファイルが 1 行ずつ読み取られ、 String[] nextline に格納されます。ここで、 nextline[i] には、解析されたファイルのそれぞれのコンテンツが入力されます。.csv ファイルの読み取りに問題はありませんでしたが、System.out.println() によってすべての行について次の結果が得られるため、それらを別の String[] に格納する必要があります。
Nextline[1]=Jan 4, 2011 18:33:15.988422000 / predata=null / Nextline[4]=54 / size:0
ご覧のとおり、Strin[] には null 値がありますが、コンテンツが渡されないのはなぜですか? 前もって感謝します
public class Amostra {
int[] id = new int[20000];
String[] predata = new String[20000];
int[] size = new int[20000];
Amostra(String namefile) throws FileNotFoundException, IOException {
Csv2Array(namefile);
}
private void Csv2Array(String newfile) throws FileNotFoundException, IOException
{
String[] nextline;
int j = 0;
int i = 0;
CSVReader reader = new CSVReader(new FileReader(newfile), ';', '\'', 1);
while((nextline = reader.readNext()) != null){
predata[i] = nextline[1];
size[i] = Integer.parseInt(nextline[4]);
id[i] = i;
i++;
System.out.println("Nextline[1]=" + nextline[1] +
" / predata=" + predata[i] +
" / Nextline[4]=" + nextline[4] +
" / size:" + size[i] + "\n");
}
}
}