0

I am trying to use the Apache CSV library to work with CSV files from another company. Sometimes the header line and other lines have trailing commas. The header also has a variable set of fields. If I use CSVParser to parse the header, it throws an exception because of the duplicate (empty) column headers created from the trailing commas. If I parse the header line manually, I am not sure how to supply the column names to the parser. It accepts an Enum, ResultSet artifacts or specific String values, but not a List, Collection or Iterable. Is there a solution that lets me use CSVParser and column titles?

4
  • 1
    Stackoverflow is for when you encounter problems while attempting to do something, not for such broad questions. You need to show what code you've written to tackle the problem and where you've gotten stuck. Commented Sep 6, 2017 at 14:47
  • I respectfully disagree. I think the problem was more clearly described conceptually, but looking for a specific call on a specific class does not seem like a broad question. Commented Sep 6, 2017 at 15:05
  • I think you should change your question title to be in a question form and actually more accurately describe your problem. For example, "How to use Apache CSV library with column titles?", would likely be much more better. Commented Sep 6, 2017 at 15:53
  • Okay, title updated. Commented Sep 6, 2017 at 18:47

1 Answer 1

1

You need to set the below parameter to true.

withAllowMissingColumnNames(true)

API is here. And make sure you are using version 1.1 or greater. Looks like this was fixed as part of a bug

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

1 Comment

I saw the discussion of that but then did not see this method. Maybe I somehow had the 1.0 javadoc. Anyway, looks like that did it.

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.