This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Problem creating CSV file with writeAll method of CSVWriter

 
Raza Mohd
Ranch Hand
Posts: 247
Java MyEclipse IDE MySQL Database
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi ,

I am having problem in writing csv file.
List<String[]> has proper values .
But when i use



It creates the Blank file with no records.
please try to help me in figuring out this problem.
 
Rob Spoor
Sheriff
Pie
Posts: 20388
46
Chrome Eclipse IDE Java Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'll be assuming the following:
- CSVWriter means au.com.bytecode.opencsv.CSVWriter, as part of opencsv
- WriteAll should be writeAll

What happens if you call csvWriter.flush() and, more importantly, csvWriter.close()? Since you should always close all your streams when you're done with them.
 
Raza Mohd
Ranch Hand
Posts: 247
Java MyEclipse IDE MySQL Database
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@Rob sorry it was my bad !
In my code it is writeAll . Still the records are not written on the file.
Is the syntax is wrong ? or whats the problem i did not getting.

 
Raza Mohd
Ranch Hand
Posts: 247
Java MyEclipse IDE MySQL Database
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks Rob.

I was not closing the streams.
 
Raza Mohd
Ranch Hand
Posts: 247
Java MyEclipse IDE MySQL Database
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
why I am not able to flust the CSVWriter object ?
whereas Writer is getting flushed.
Can not get flush method for CSVWriter object.
Is there any specific reason for that?
 
Ulf Dittmer
Rancher
Pie
Posts: 42966
73
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What do you mean by "Can not get flush method for CSVWriter object. "? If there is an error message, post it here along with the code that causes it.
 
Raza Mohd
Ranch Hand
Posts: 247
Java MyEclipse IDE MySQL Database
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I mean
- In my eclipse IDE when i use intellisense(CTRL + Space) it does not show flush method for CSVWriter object but gives for Writer object.

that is my code.
 
Ulf Dittmer
Rancher
Pie
Posts: 42966
73
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The important question is what happens during compilation - does that work?

If you want to know what methods a class has, check the javadocs; that's the ultimate reference, not what the IDE thinks.
 
Raza Mohd
Ranch Hand
Posts: 247
Java MyEclipse IDE MySQL Database
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
when i write this


compilation fails.
and says the method flush() is undefined for type CSVWriter.

 
Ulf Dittmer
Rancher
Pie
Posts: 42966
73
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try compiling on the command line, and make sure that the opencsv jar file you're using isn't corrupted - the javadocs say that the method exists.
 
Raza Mohd
Ranch Hand
Posts: 247
Java MyEclipse IDE MySQL Database
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
same error in the command line.
Compilation fails.
What is that issue?

compilation error in command line is::
cannot fine symbol
symbol: method flush()
 
Ulf Dittmer
Rancher
Pie
Posts: 42966
73
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You should call flush and close on "reconWriter", not on "w".
 
Raza Mohd
Ranch Hand
Posts: 247
Java MyEclipse IDE MySQL Database
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I tried it too .
But i am unable to find it compiled .
what can be the reason Ulf?
 
Ulf Dittmer
Rancher
Pie
Posts: 42966
73
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But i am unable to find it compiled .

What does this mean? Does it or does it not compile?
 
Raza Mohd
Ranch Hand
Posts: 247
Java MyEclipse IDE MySQL Database
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It did not compile.
 
Ulf Dittmer
Rancher
Pie
Posts: 42966
73
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Then there would have been an error message that tells you what went wrong; tell us what that was. Also tell us what command you used to compile the code. (If you're still using an IDE, make sure you understand where that IDE would put compiled class files, and check whether that's where they are.)

And just to make sure: You have checked that the class file didn't end up in a different subdirectory than you expected, right? Packages are involved, after all.
 
Raza Mohd
Ranch Hand
Posts: 247
Java MyEclipse IDE MySQL Database
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I did it in command prompt.
compilation error in command line is::
cannot fine symbol
symbol: method flush()



And in IDE the error message is::
flush() is undefined for type CSVWriter
 
Ulf Dittmer
Rancher
Pie
Posts: 42966
73
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I just tried, and found that the following code compiles fine. It's the same you're using, minus any stuff that deals with classes that are not present; maybe you can work your way from there towards your code, and that way find out where the problem originates.
 
Raza Mohd
Ranch Hand
Posts: 247
Java MyEclipse IDE MySQL Database
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ok fine!
and thanks for your help.!
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic