Converting CSV File Into 2D Array

前端 未结 5 1710
南笙
南笙 2021-01-19 03:45

I have an example of my idea in a 1d array. It will only output the columns. My idea is to use a 2d array to select the row and column. Here my code:

String          


        
5条回答
  •  萌比男神i
    2021-01-19 04:21

    It's better to use an ArrayList of 1D String arrays, instead of a 2D String array.

    String fName = "c:\\csv\\myfile.csv";
    String thisLine;
    FileInputStream fis = new FileInputStream(fName);
    DataInputStream myInput = new DataInputStream(fis);
    ArrayList strar = new ArrayList();
    
    while ((thisLine = myInput.readLine()) != null) {
        strar.add(thisLine.split(";"));
    }
    

    Note: Also you need to handle the IOException here.

提交回复
热议问题