开发者

Pass values String[] to String[] values

I have the following code, where a .csv file is read, line by line, and stored in String[] nextline , where the nextline[i] is populated by the respective content of the parsed file. I got no problems in reading the .csv file, but i do have in storing them in another String[], since the System.out.println() gives me the following result, for all the lines:

Nextline[1]=Jan  4, 2011 18:33:15.988422000 / predata=null / Nextline[4]=54 / size:0

As you can see, the Strin[] has null value, why the cont开发者_StackOverflow社区ent is not passed? Thanks in advance

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");
        }
    }
}


Your i++ statement is located before the System.out so you are actually printing the next line (not parsed yet). You should move the i++ line after the System.out

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜