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();
}
私が不足しているところを私に提案しますか?