如何将SQLite数据库表导出到Android中的csv文件中

时间:2015-04-13 20:53:05

标签: android export-to-csv

我想将SQLite数据库表导出到.csv文件中。当我导出数据库时,它导出成功所有记录将完全显示在我的手机中,但问题是当我将.csv文件从我的手机复制到我的电脑时,一些数据会丢失。 .csv文件不会根据数据增加其大小。问题是什么 ?我的代码如下: -

File  outFile = new File(DATABASE_DIRECTORY, outFileName);
            FileWriter fileWriter = new FileWriter(outFile);

        BufferedWriter out = new BufferedWriter(fileWriter);

        Cursor cursor = controller.getInfo();

    //  int col_count = cursor.getColumnCount();


        csvHeader += "" + "id" + ",";
        csvHeader += "" + "name" + ",";
        csvHeader += "" + "class" + ",";
        csvHeader += "" + "div" + "";
        csvHeader += "\r\n";

        if (cursor != null) {
            out.write(csvHeader);
            while (!cursor.isAfterLast()) {

                csvValues = cursor.getString(0) + ","; 
                csvValues += cursor.getString(1) + ","; 
                csvValues += cursor.getString(2) + ","; 
                csvValues += cursor.getString(3) + ","; 

                out.write(csvValues);


                cursor.moveToNext();
            }


        }

        out.close();
        cursor.close();
        returnCode = true;

0 个答案:

没有答案