Read large CSV in java

前端 未结 3 945
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-03 22:53

I want to read huge data from CSV, containing around 500,000 rows. I am using OpenCSV library for it. My code for it is like this

    CsvToBean c         


        
3条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-03 23:59

    Read line by line

    something like this

        CSVReader reader = new CSVReader(new FileReader("yourfile.csv"));
        String [] nextLine;
        while ((nextLine = reader.readNext()) != null) {
            // nextLine[] is an array of values from the line
            System.out.println(nextLine[0] + nextLine[1] + "etc...");
        }
    

提交回复
热议问题