简体   繁体   English

如何将数据从数据库导出到csv文件?

[英]How can I export datas from my database to a csv file?

I'm working on an android project and a part of it is to export datas from my database to a csv file. 我正在开发一个android项目,其中一部分是将数据库中的数据导出到csv文件中。

I already read a lot of thread especially opencsv and try this: 我已经读了很多线程,尤其是opencsv并尝试这样做:

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. 文件已创建,但大小为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. 我使用append来添加一些信息,但是我遇到了同样的问题。

Is anybody has another way to figure this out or what I missed in the example above? 是否有人有其他方法可以解决这个问题,或者我在上面的示例中错过了什么?

Is your file really empty ? 您的文件真的是空的吗? depending on the data you're exporting, your file may indeed be much less than 1K. 根据您导出的数据,文件的确可能小于1K。 I must admit I don't know android so I don't know how it handles very small files size indication... 我必须承认我不知道android,所以我不知道它如何处理很小的文件大小指示...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM