0

I have this CSV file that I want to read:

ID;Name;Age
GEORGE;GEORGE;19
JOHN;JOHNNY;45
MARCO;MARCO POLO;32

I also have to read it using this command:

for (CSVRecord rec : CSVFormat.DEFAULT.withDelimiter(';').parse(in)) {
    //some code
}

I don't want to read the first line, because it's just the description of what contain the fields

I also tried to find the resolution of this in stackoverflow and other sites, but I didn't find how to do it.

EDIT 1: I imported CSVRecord and CSVFormat from org.apache.commons.csv.CSVFormat and org.apache.commons.csv.CSVRecord

EDIT 2: My post is not a duplicate because I'm asking about a library, just as @slim commented

7
  • What is that CSVRecord, and CSVFormat? You have to show us more of what you have. Commented Sep 27, 2016 at 15:46
  • @E_net4 sorry, I edited my question, now you can know Commented Sep 27, 2016 at 15:50
  • Possible duplicate of Skip first line while reading CSV file in Java Commented Sep 27, 2016 at 15:51
  • Please tell us which CSV library do you use. Commented Sep 27, 2016 at 15:52
  • Probably use CSVFormat#withSkipHeaderRecord(true) Commented Sep 27, 2016 at 15:53

2 Answers 2

4

See the "Working with headers" section of the user guide.

Specifically, you can configure the parser to know that the first line is a header, using CSVFormat.withFirstRowAsHeader()

Sign up to request clarification or add additional context in comments.

Comments

1

There are many stackoverflow resources for this question. Skip first line while reading CSV file in Java seems like the best resource for your answer.

1 Comment

Also, if you are interested in only using CSVRecord, the solution provided for 'Read from CSV File' would do the trick!

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.