Java tutorial
//package com.java2s; import java.io.File; import android.util.Log; public class Main { private final static int MAX_BACKUP_FILES = 5; public static void moveCorruptedFileToBackup(File f) { if (!f.exists()) return; Log.e("cr3", "Moving corrupted file " + f + " to backup."); File backup = getBackupFileName(f, false); f.renameTo(backup); } private static File getBackupFileName(File f, boolean isGoodBackup) { File f2 = null; String prefix = f.getAbsolutePath() + (isGoodBackup ? ".good.bak." : ".corrupted.bak."); for (int i = MAX_BACKUP_FILES - 1; i > 2; i--) { File to = new File(prefix + i); File from = new File(prefix + (i - 1)); if (to.exists()) to.delete(); if (from.exists()) { if (!from.renameTo(to)) Log.e("cr3", "Cannot rename DB file " + from + " to " + to); } } f2 = new File(prefix + 2); if (f2.exists()) if (!f2.delete()) Log.e("cr3", "Cannot remove DB file " + f2); return f2; } }