Good and effective CSV/TSV Reader for Java

后端 未结 4 1254
南笙
南笙 2021-01-11 09:27

I am trying to read big CSV and TSV (tab-separated) Files with about 1000000 rows or more. Now I tried to read a TSV cont

4条回答
  •  生来不讨喜
    2021-01-11 10:12

    Try switching libraries as suggested by Satish. If that doesn't help, you have to split the whole file into tokens and process them.

    Thinking that your CSV didn't had any escape characters for commas

    // r is the BufferedReader pointed at your file
    String line;
    StringBuilder file = new StringBuilder();
    // load each line and append it to file.
    while ((line=r.readLine())!=null){
        file.append(line);
    }
    // Make them to an array
    String[] tokens = file.toString().split(",");
    

    Then you can process it. Don't forget to trim the token before using it.

提交回复
热议问题