Menu

#39 Problems with opencsv and Grails 2

v1.0 (example)
closed
Opal
None
5
2016-04-27
2016-04-01
No

I'm a relative newbie with Grails and opencsv. However, I have managed to use CSVReader fine and am able to read csv files and use them in my controllers just fine.

However, if I try to use the CSVWriter I just get an error when the following line is encountered -

CSVWriter writer = new CSVWriter(new FileWriter("/yourfile.csv"), '\t');

Error is -

Could not find matching constructor for: com.opencsv.CSVWriter(java.io.FileWriter, java.lang.String)

I have imported what I think I need to import, ie

import java.io.File
import java.io.FileWriter
import java.io.IOException
import com.opencsv.CSVReader
import com.opencsv.CSVWriter

Grails version is 2.1.1
Netbeans development environment

Any ideas? I've tried all sorts of variations to the above and just cannot instantiate the writer.

Discussion

  • Opal

    Opal - 2016-04-01

    '\t' in grails will be recognized as an instance of String and in fact there's no such constructor that takes Writer and String try:

    CSVWriter writer = new CSVWriter(new FileWriter("/yourfile.csv"), '\t' as char);

     
    • Simon Edwards

      Simon Edwards - 2016-04-01

      Woo hoo! That's done the trick. I now don't get the error, and I'm able to carry on with my project.

      Many thanks indeed for this pointer, and for the super fast response.

       
  • Andrew Rucker Jones

    • status: open --> closed
    • assigned_to: Opal
     

Log in to post a comment.

MongoDB Logo MongoDB