how to read csv file without knowing header using java?

前端 未结 3 886
慢半拍i
慢半拍i 2020-12-22 09:15

i have to read CSV file in java, I googled it but i got the way to read using the headers; but i have no information of the column headers and number of columns available i

3条回答
  •  北海茫月
    2020-12-22 10:07

    If you don't know what the columns represent you can only read it as text with something like:

    final BufferedReader br = new BufferedReader(new FileReader(file));
    String line = null;
    while ((line = br.readLine()) != null) {
    
        final String[] lineValues = line.split(COLUMN_DELIMITER);
    }
    

    This way all your column values will be in these lineValues arrays (column1 will be lineValues[0] etc.).

提交回复
热议问题