如何以csv格式将数据库文件从模拟器存储到sdcard?
我已经创建了这个类,但我不知道应该在哪里调用它。
public class MyDatabaseTools {
private String appName = "LogCard";
private String packageName = "com.android.logcard";
SQLiteOpenHelper sqlitehelper;
public boolean backup() {
boolean rc = false;
boolean writeable = isSDCardWriteable();
if (writeable) {
File file = new File(Environment.getDataDirectory() + "/data/" + packageName + "/databases/" + sqlitehelper.getDatabaseName());
File fileBackupDir = new File(Environment.getExternalStorageDirectory(), appName + "/backup");
if (!fileBackupDir.exists()) {
fileBackupDir.mkdirs();
}
if (file.exists()) {
File fileBackup = new File(fileBackupDir, sqlitehelper.getDatabaseName());
try {
fileBackup.createNewFile();
FileUtils.copyFile(file, fileBackup);
rc = true;
} catch (IOException ioException) {
//
} catch (Exception exception) {
//
}
}
}
return rc;
}
private boolean isSDCardWriteable() {
boolean rc = false;
String state = Environment.getExternalStorageState();
if (Environment.MEDIA_MOUNTED.equals(state)) {
rc = true;
}
return rc;
}
public MyDatabaseTools(final Context context, final String appName) {
this.appName = appName;
packageName = context.getPackageName();
}
如果有帮助的话,应该在哪里调用这个类;我从这里拿了这段代码