1

I'm working on an android project and a part of it is to export datas from my database to a csv file.

I already read a lot of thread especially opencsv and try this:

CSVWriter writer = null;
    try {
        writer = new CSVWriter(my file name);
        // just an example
        String[] entries = "1,2,3,4,5,6".split(",");
        writer.writeNext(entries);
    } catch (IOException e) {
        // TODO: handle exception
    }

The file is created but his size is 0KB.

I try to figure it out with another way. See the Code below:

 File myFile = new File(my file name);

        myFile.createNewFile();
        FileOutputStream fOut = new FileOutputStream(myFile);
        OutputStreamWriter myOutWriter = new OutputStreamWriter(fOut);

And I used append to put some piece of information but I've got the same problem.

Is anybody has another way to figure this out or what I missed in the example above?

3
  • 1
    There are hundreds of existing CSV parsers out there, why not try one of those? (Or at least check the code they use for direction/inspiration.) It's pretty easy to create a naive one on your own (See this for example: stackoverflow.com/questions/5360628/…) but most of those fail as soon as one of the strings in your input has commas (or even escape chars too) in it. Mar 28, 2013 at 16:28
  • Thanks a lot @CharlieCollins escape chars was the problem
    – 13KZ
    Mar 28, 2013 at 16:50
  • Please follow the links in given Question comments tht r upvoted [Here][1] [1]: stackoverflow.com/questions/21448001/…
    – Aditi K
    Jan 31, 2014 at 4:53

1 Answer 1

0

Is your file really empty ? depending on the data you're exporting, your file may indeed be much less than 1K. I must admit I don't know android so I don't know how it handles very small files size indication...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.