开发者

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', '\'');
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜