我有以下代码用于创建SQLite数据库的备份;
File sd = Environment.getExternalStorageDirectory();
File data = Environment.getDataDirectory();
FileChannel source = null;
FileChannel destination = null;
String currentDBPath = "/data/com.sjhdevelopment.shaunharrison.myejuiceapp/databases/EJuiceData.db";
String backupDBPath = "EJuiceData.db";
File currentDB = new File(data,currentDBPath);
File backupDB = new File(sd,backupDBPath);
try
{
source = new FileInputStream(currentDB).getChannel();
destination = new FileOutputStream(backupDB).getChannel();
destination.transferFrom(source,0,source.size());
source.close();
destination.close();
Toast.makeText(this, "DB Exported", Toast.LENGTH_LONG).show();
}
catch(Exception e)
{
showError("Error", e.getMessage());
}
我有以下代码来导入SQLite数据库
File sd = Environment.getExternalStorageDirectory();
File data = Environment.getDataDirectory();
if(sd.canWrite())
{
String currentDBPath="/data/com.sjhdevelopment.shaunharrison.myejuiceapp/databases/EJuiceData.db";
String backupDBPath = "EJuiceData.db";
File backupDB = new File (data,currentDBPath);
File currentDB = new File(sd, backupDBPath);
try {
FileChannel src =new FileInputStream(currentDB).getChannel();
FileChannel dst = new FileOutputStream(backupDB).getChannel();
dst.transferFrom(src, 0, src.size());
src.close();
dst.close();
Toast.makeText(getBaseContext(), "DB Imported", Toast.LENGTH_LONG).show();
}
catch(Exception e)
{
showError("Error", e.getMessage());
}
我的问题是我现在希望用户能够进行多次备份而不仅仅是一次备份,我知道如何通过以下方式获取今天的日期;
Calendar calendar = Calendar.getInstance();
Date today = calendar.getTime();
DateFormat dateFormat = new SimpleDateFormat("dd/MMM/yyyy");
String todayAsString = dateFormat.format(today);
但是在代码导出代码中今天asString的位置是什么?
此外,在导入时如何允许用户浏览其文件以选择要导入的备份?
由于