Read "string" separated values using Opencsv
Is it possible to read a csv file where the values are separated by a string rather than a single character? Earlier the csv file had a comma separator, but now it is being created with a string separator "###". I don't have any control over the creation of the csv file.
I'm using the Opencsv library http://sourceforge.net/projects/opencsv/ and it does not seem to have support for string separator only characters.
开发者_StackOverflow社区Is there a way to solve the above? Are there any good and similar alternatives to the Opencsv library?
The docs give you an example of how to do this. See http://opencsv.sourceforge.net/#custom-sepators.
Can I use my own separators and quote characters?
Yes. There are constructors that cater for supplying your own separator and quote characters. Say you're using a tab for your separator, you can do something like this:CSVReader reader = new CSVReader(new FileReader("yourfile.csv"), '\t');
And if you single quoted your escaped characters rather than double quote them, you can use the three arg constructor:
CSVReader reader = new CSVReader(new FileReader("yourfile.csv"), '\t', '\'');
精彩评论