0

Does anyone know how to read a csv file. Isn't it just like reading a regular .txt file or is there more to it?

2
  • 1
    Get help from a framework. There are plenty of them around. One candidate is Apache Commons CSV. Commented Nov 22, 2017 at 17:07
  • You can read it just like a regular .txt file, but it depends on what you want to do with it I guess? A scanner over the .csv would work, but it wouldn't split it on on comma's by default ;) Commented Nov 22, 2017 at 17:07

1 Answer 1

1

I hope this helps -> https://www.mkyong.com/java/how-to-read-and-parse-csv-file-in-java/

So basically there are three major options from which you can select.

  1. Simple Solution: If you are sure the CSV files doesn’t contain “separator or double-quotes”, just use the standard split() to parse the CSV file.

  2. Advance Solution: This solution will solve the field containing “separator or double-quotes” issue, and also support the custom separator and custom enclosed field. Review the following CSV parsing example and also the JUnit test cases to understand how it works.

  3. OpenCSV Example: If you are not comfortable with above simple and advance solution, try using third party CSV library – OpenCSV.

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

Comments

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.