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?

13KZ
  • 1,295
  • 5
  • 24
  • 43
  • 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: http://stackoverflow.com/questions/5360628/get-and-parse-csv-file-in-android) but most of those fail as soon as one of the strings in your input has commas (or even escape chars too) in it. – Charlie Collins Mar 28 '13 at 16:28
  • Thanks a lot @CharlieCollins escape chars was the problem – 13KZ Mar 28 '13 at 16:50
  • Please follow the links in given Question comments tht r upvoted [Here][1] [1]: http://stackoverflow.com/questions/21448001/how-to-implement-export-sqlite-to-excel-csv-file-in-android – Aditi K Jan 31 '14 at 04:53

1 Answers1

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...

Laurent S.
  • 6,816
  • 2
  • 28
  • 40