1

Do I need a library if I only need to make csv formatted file. I don't need reading and parsing it.

Nick
  • 820
  • 2
  • 14
  • 29

2 Answers2

2

No, you don't. And even reading/parsing can be easily done with a plain JRE.

CSV is a plain (ascii-)text format with only a few rules:

  • rows (objects) are separated with a \n
  • columns (fields, attributes) are spearated with a delimiter char (usually a comma, but define whatever you need)
  • row and column delimiters must not be part of the field values
Andreas Dolk
  • 113,398
  • 19
  • 180
  • 268
  • At least I've decided not to use any libraries) – Nick Feb 15 '11 at 14:38
  • That is so bad. Of course you are right. But why does everyone have to implement this manually? Why isn't there just a simple class in the Java collections or io API that does this?? I'm sick of having to think of escaping `";", ",", "\t", "\""` and all that again and again... :-( – Lukas Eder Jun 24 '11 at 09:39
  • @Lukas Eder - why don't you just implement your own private toolbox that has, amongst other stuff, some static helper methods for csv files ;-) – Andreas Dolk Jun 25 '11 at 21:39
  • Well I do. Time and again ;-) – Lukas Eder Jun 28 '11 at 17:25
  • Don't forget platform-specific line terminators (*N.B.* fields can contain line terminators), and quoting. – user359996 Nov 30 '12 at 20:13
1

Unless it's a really trivial part of your application and you're absolutely sure you won't ever need to parse a CSV file, you need a CSV-serialization library.

I have tried openCSV and I'm pretty happy using it. Of course you can write your own class to handle this serialization, but a library always comes with more features at the expense of an extra dependency...

Pantelis Sopasakis
  • 1,902
  • 5
  • 26
  • 45