1

I've tried to create my reader like this:

CSVReader reader = new CSVReader(new FileReader("ping10102012.csv"), '\t');

int i=0;
while ( (nextLine = reader.readNext()) != null){
    System.out.println(nextLine[i]); // Debug only
}

And I'm having some issues with stuff. I'm only getting the first(column) values from my csv, and they're outputting pretty weird.

output:

I  D
2  7  2  2  2
2  4  6  9  4
...more like this

The columns are:

UnitId

Attempts

ACPower

etc. etc. Thanks for any help!

2
  • Thanks for any help! -> We cannot help without a question.. and some more explanation.. Commented Oct 11, 2012 at 15:32
  • @ Damien.Bell : Your file may not be tab separated? Please show actual file and actual code.. Commented Oct 11, 2012 at 15:39

1 Answer 1

2

You are printing first column only as all the time as i=0 and there is no change in value assigned to i.

Try this:

         while ( (nextLine = reader.readNext()) != null){
            for(String value: nextLine){
               System.out.println(value); // Debug only
            }
        }
Sign up to request clarification or add additional context in comments.

2 Comments

Huge derp moment on that one. I'm still having a small issue where I'm getting an java.lang.ArrayIndexOutOfBoundsException: 1. I'm not entirely sure why that's happening
Updated the answer to use for loop to print the column values. Its check the length internally. Hope that helps.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.