我正在使用这种方法将我的 db 文件复制到 sd car 请告诉我 sdcard 上的文件是否已经存在,那么它将替换还是不会复制?
public boolean copyDbToSDCard() {
boolean success = false;
String SDCardPath = Environment.getExternalStorageDirectory()
.getAbsolutePath();
final String DBPATH = SDCardPath + "/BD/";
final String DBNAME = "Mydb3.db";
this.getReadableDatabase();
File directory = new File(DBPATH);
if (!directory.exists())
directory.mkdir();
close();
try {
InputStream mInput = new FileInputStream(DB_PATH + DB_NAME);
OutputStream mOutput = new FileOutputStream(DBPATH + DBNAME);
byte[] buffer = new byte[1024];
int length;
while ((length = mInput.read(buffer)) > 0) {
mOutput.write(buffer, 0, length);
}
mOutput.flush();
mOutput.close();
mInput.close();
success = true;
} catch (Exception e) {
Toast.makeText(myContext,
"copyDbToSDCard Error : " + e.getMessage(),
Toast.LENGTH_SHORT).show();
e.fillInStackTrace();
}
return success;
}