Java 如何将数据库的所有值发送到outputstream

Java 如何将数据库的所有值发送到outputstream,java,sqlite,Java,Sqlite,我有一个名为MyDb的SQLiteDatabase对象。可以通过调用insertLocation方法来填充此对象 public boolean insertLocation(String time, double latitude, double longitude) { SQLiteDatabase db = this.getWritableDatabase(); ContentValues cV = new ContentValues(); c

我有一个名为MyDb的SQLiteDatabase对象。可以通过调用insertLocation方法来填充此对象

public boolean insertLocation(String time, double latitude, double longitude) {
        SQLiteDatabase db = this.getWritableDatabase();
        ContentValues cV = new ContentValues();
        cV.put("time", time);
        cV.put("latitude", latitude);
        cV.put("longitude", longitude);
        db.insert("location", null, cV);
        return true;
    }
现在我想把所有这些数据放到outputstream,我应该怎么做呢?

在返回之前

PrintWriter printWriter = new PrintWriter(file); 
printWriter.println("time=" + time);
printWriter.println("latitude=" +latitude);
printWriter.println("longitude=" + longitude);

我希望这能有所帮助

是否要在outputStream中发送数据库中的所有条目

我正试图找到更好的方法,但我能想到的是:

public void saveDatabaseAsTextFile() {

    // Get a cursor of the data
    Cursor c = doYourQuery();
    if (c.moveToFirst()) {
        try {
            OutputStreamWriter writer = new OutputStreamWriter(
                openFileOutput("locations.txt", Context.MODE_PRIVATE));
            // For each position of the cursor, create a comma
            // delimited string (with a new line char at the end).
            String line;
            do {
                line = "";
                line = line.concat(c.getString(c
                        .getColumnIndex("time")) + ",");
                line = line.concat(c.getDouble(c
                        .getColumnIndex("latitude")) + ",");
                line = line.concat(c.getDouble(c
                        .getColumnIndex("longitude")) + "\n");
                // send the string to the OutputStreamWriter
                writer.write(line);
            } while (c.moveToNext());
            // close the OutputStreamWriter
            writer.close();
        } catch (IOException e) {
            Log.e("Exception", "File write failed: " + e.toString());
        }
    }
}
如果不想写入文件,请将该字符串扔到其他输出流