0

次のコードがあります。.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");
        }
    }
}
4

1 に答える 1

6

i++ステートメントは の前にあるSystem.outため、実際には次の行を出力しています (まだ解析されていません) 。i++の後に行を移動する必要がありますSystem.out

于 2011-05-06T09:54:41.867 に答える