1

DBをバックアップしたいのですが、Googleで動作しているように見えるコードを見つけましたが、DBのエントリではなく、DB構造をバックアップしています。

エラーは報告されていません。また、テーブルをCSV形式でエクスポートするにはどうすればよいですか。

DBをバックアップするためのコード:

public void BackupDB() {
 InputStream myInput;

    try {

        myInput = new FileInputStream("/data/data/com.cecchina.mathew.lessonsDB/databases/Teaching");
        // Set the output folder on the SDcard
        File directory = new File("/mnt/sdcard/external_sd/TeachingBKup/");
        // Create the folder if it doesn't exist:
        if (!directory.exists()) 
        {
            directory.mkdirs();
        } 
        // Set the output file stream up:

        OutputStream myOutput = new FileOutputStream(directory.getPath()+ "/Teaching.backup");
        // Transfer bytes from the input file to the output file
        byte[] buffer = new byte[1024];
        int length;
        while ((length = myInput.read(buffer))>0)
        {
            myOutput.write(buffer, 0, length);
        }
        // Close and clear the streams
        myOutput.flush();

        myOutput.close();

        myInput.close();

    } catch (FileNotFoundException e) {
Toast.makeText(ourContext, "Backup Unsuccesfull file not found error!",          Toast.LENGTH_LONG).show();
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
Toast.makeText(ourContext, "Backup Unsuccesfull IO error!", Toast.LENGTH_LONG).show();
// TODO Auto-generated catch block
        e.printStackTrace();
    }
Toast.makeText(ourContext, "DataBase structure backed up!", Toast.LENGTH_LONG).show();

} 

私が不足しているところを私に提案しますか?

4

1 に答える 1

0

データを挿入する前にバックアップを作成した場合、もちろん、取得するのは構造(配置したとおり)だけです。

コードは完全なファイルをコピーするため、データベースにデータがある場合は、カードにコピーされます。

いくつかのアプリでバックアップを実行するために、ほぼ同じコード(メニュー項目から起動)を使用しています。復元/インポートするコードもあり、すべてのデータがそこにあります。

于 2012-06-07T16:21:07.013 に答える