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?
-
1Get help from a framework. There are plenty of them around. One candidate is Apache Commons CSV.Henrik Aasted Sørensen– Henrik Aasted Sørensen2017-11-22 17:07:04 +00:00Commented 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 ;)MrHug– MrHug2017-11-22 17:07:05 +00:00Commented Nov 22, 2017 at 17:07
1 Answer
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.
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.
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.
OpenCSV Example: If you are not comfortable with above simple and advance solution, try using third party CSV library – OpenCSV.