Java Library to Read CSV and Specify Custom Delimiter More Than 1 char(string) %



Need to read a CSV file with custom string delimiter like "|%|". Currently I am using CSV commons library, but it only allows splitting by char and not string. I would prefer splitting by sticking to CSV commons library, but open to other libraries as well.


You need to read a CSV file by the user-defined delimiter (a string instead of a character). It is roundabout to do this in Java.

But it is very simple to get this done using SPL, an open-source Java package. Only one line of code is enough:





SPL offers JDBC driver to be invoked by Java. Just store the above SPL script as readcsv.splx and invoke it in Java as you call a stored procedure:


con= DriverManager.getConnection("jdbc:esproc:local://");

st=con.prepareCall("call readcsv ()");


Or execute the SPL string within a Java program as we execute a SQL statement:

st = con.prepareStatement("==file(\"custom.csv\").import@t (;,\"|%|\")");

View SPL source code.