• Post Reply Bookmark Topic Watch Topic
  • New Topic

Writing in different columns with opencsv  RSS feed

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

I'm using opencsv and I want to write two arrays into a csv file and each array should be in a column. For example:

Column1 Column2
2423542 2332332
5242324 4343434
4242352 7565656
4343434 6565656



With my code the arrays are all in one column. What do I have to change that my output will be in two columns?


Thanks for your help!
 
Master Rancher
Posts: 2044
75
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi Michael,

I just had a read on this opencsv. The example given there is

You see that a '\t' is used as a separator. You use '\n', so that means that a newline
is used. No wonder everything ends up in the same column!

I'm not sure how you can write two arrays, side by side, since the example
writes an array on the same line, not individual items. If it gives you problems,
then maybe you can write your data out with a simple Java filewriter. That is
very easy as well.

Greetz,
Piet
 
Michael Hoffmann
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your help!

Here is my result and it works perfectly.

 
Piet Souris
Master Rancher
Posts: 2044
75
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Michael Hoffmann wrote:Thanks for your help!
(...)

You're welcome! And well done.

A small remark: in this line:

you don't need the last '\t', since wec[i] is the last item
on this line. It can be followed by the newline, which you
do in your next line.

Greetz,
Piet
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!