javaparsingcsvopencsv

Parsing a CSV file with custom String separator


I tried to parse a CSV file with two APIs - JSefa and OpenCSV - but the problem is that the separator in the CSV file is a double tab "\t\t" and the APIs only accept a character, not a string, for the separator.

Is there any other API that could solve the problem, or there s a way to determine a new String separator in Jsefa or OpenCSV?

As a last resort I could, before parsing, try to replace the double tab by a semicolon but I was hoping to do it a cleaner way.


Solution

  • There's 101 examples online. I Googled "java parse csv" and this was the #1 result:

    http://www.mkyong.com/java/how-to-read-and-parse-csv-file-in-java/

    That uses a String as a separator, however this is code rather than an API.

    Given that parsing a CSV file is a pretty simple process, I don't think it's a good example of a situation requiring a library and - especially with a slightly unique requirement like you have with the strange \t\t separator - it is probably better to just code it anyway.