Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

My Java program doesn't iterate through my entire CSV file

Tags:

java

csv

Code:

import java.io.BufferedReader;
import java.io.FileReader;
import java.util.Scanner;

public class dataReader {

    @SuppressWarnings("rawtypes")
    public static void main(String[] args) throws Exception {
        String splitBy =",";
        BufferedReader br = new BufferedReader(new FileReader("C:/practice/testData.csv"));
        String line = br.readLine();
        int counter = 0;

        while ((line = br.readLine()) != null){
            counter++;
            String[] b = line.split(splitBy);

            for (int x = 0; x < b.length; x++){
                System.out.println(b[x]);
            }


        }
        System.out.println(counter);
        br.close();
    }   
}

When I run it, it goes through the CSV and displays some output but it starts with product ID 4000+. It basically only outputs results for the last thousand rows in the CSV. I'm wrangling with a really ugly CSV file to try to get some useful data out of it so that I can write all of it into a new database later on. I'd appreciate any tips.

like image 489
HandleThatError Avatar asked Dec 29 '25 01:12

HandleThatError


1 Answers

As in the comments, the issue is that System.out.println prints to your console. The console will have a limit to the number of lines it can display, which is why you see the last ~1000 lines.

like image 109
Kevin Avatar answered Dec 31 '25 18:12

Kevin



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!