34

Possible Duplicate:
CSV API for Java
Can you recommend a Java library for reading (and possibly writing) CSV files?

I am wondering if there is a good library that supports reading and writing csv files?

Community
  • 1
  • 1
user705414
  • 20,472
  • 39
  • 112
  • 155
  • 6
    @SamirMangroliya There is a lot of stuff out there. He is asking for an opinion. There is nothing wrong with that and it is a legitimate question. – MarianP May 05 '12 at 14:46
  • 3
    @MarianP unfortunately (I had to learn and accept this too) asking for opinions or recommendations is not very welcome at SO: http://stackoverflow.com/help/dont-ask – Marged Jun 17 '15 at 20:35

3 Answers3

19

http://opencsv.sourceforge.net/

Francis Upton IV
  • 19,322
  • 3
  • 53
  • 57
  • 2
    Yup that one works. Only drawback (I found) is that it does not handle file encoding directly and I am unsure if there is a well-known csv-file encoding. – Guillaume Polet May 05 '12 at 14:02
  • 1
    The file encoding is really not dependent on CSV, it depends mainly on the environment/program where the file is written. So there is not a well established encoding. – Francis Upton IV May 05 '12 at 14:17
19

I use Apache Commons CSV. http://commons.apache.org/csv/

There is also Super CSV, but I haven't tried it. http://super-csv.github.io/super-csv/

It is also not such a big deal to write something on your own IMO.

Arnost Valicek
  • 2,418
  • 1
  • 18
  • 14
MarianP
  • 2,719
  • 18
  • 17
  • 48
    Well, there are a few cases with quotes and escaping, so it's a little more than meets the eye. – Francis Upton IV May 05 '12 at 14:01
  • 16
    It's usually a bad idea to write your own for something standard, especially when there's multiple libraries available. If you do write your own please take a look at the RFC: https://tools.ietf.org/html/rfc4180 – rhinoinrepose Dec 05 '16 at 21:24
8

I would recommend to use opencsv

What is opencsv?

opencsv is a very simple csv (comma-separated values) parser library for Java.

Pau Kiat Wee
  • 9,485
  • 42
  • 40