aspose file tools*
The moose likes Java in General and the fly likes Problem creating CSV file with writeAll method of CSVWriter Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Problem creating CSV file with writeAll method of CSVWriter" Watch "Problem creating CSV file with writeAll method of CSVWriter" New topic
Author

Problem creating CSV file with writeAll method of CSVWriter

Raza Mohd
Ranch Hand

Joined: Jan 20, 2010
Posts: 247

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.


Good luck!!
A small leak can sink a Gigantic ship.>
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19722
    
  20

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.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Raza Mohd
Ranch Hand

Joined: Jan 20, 2010
Posts: 247

@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

Joined: Jan 20, 2010
Posts: 247

thanks Rob.

I was not closing the streams.
Raza Mohd
Ranch Hand

Joined: Jan 20, 2010
Posts: 247

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
Marshal

Joined: Mar 22, 2005
Posts: 42289
    
  64
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.


Ping & DNS - my free Android networking tools app
Raza Mohd
Ranch Hand

Joined: Jan 20, 2010
Posts: 247

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
Marshal

Joined: Mar 22, 2005
Posts: 42289
    
  64
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

Joined: Jan 20, 2010
Posts: 247

when i write this


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

Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42289
    
  64
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

Joined: Jan 20, 2010
Posts: 247

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
Marshal

Joined: Mar 22, 2005
Posts: 42289
    
  64
You should call flush and close on "reconWriter", not on "w".
Raza Mohd
Ranch Hand

Joined: Jan 20, 2010
Posts: 247

I tried it too .
But i am unable to find it compiled .
what can be the reason Ulf?
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42289
    
  64
But i am unable to find it compiled .

What does this mean? Does it or does it not compile?
Raza Mohd
Ranch Hand

Joined: Jan 20, 2010
Posts: 247

It did not compile.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42289
    
  64
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

Joined: Jan 20, 2010
Posts: 247

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
Marshal

Joined: Mar 22, 2005
Posts: 42289
    
  64
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

Joined: Jan 20, 2010
Posts: 247

ok fine!
and thanks for your help.!
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Problem creating CSV file with writeAll method of CSVWriter