我想創建我的數據庫的備份,但我的手機上沒有SDCARD。我想創建在內部存儲備份,但接下來的代碼失敗......無SD卡創建備份數據庫
try {
File sd = Environment.getExternalStorageDirectory();
File data = Environment.getDataDirectory();
if (sd.canWrite()) {
String currentDBPath = "//storage//sdcard0//MyApp//turnos.db";
String backupDBPath = "turnos.db";
File currentDB = new File(data, currentDBPath);
File backupDB = new File(sd, backupDBPath);
if (currentDB.exists()) {
FileChannel src = new FileInputStream(currentDB).getChannel();
FileChannel dst = new FileOutputStream(backupDB).getChannel();
dst.transferFrom(src, 0, src.size());
src.close();
dst.close();
}
} mensajeOK("INFO", "Copia creada.");
} catch (Exception e) {
Toast.makeText(getBaseContext(), e.toString(), Toast.LENGTH_LONG).show();
}
我有權限WRITE_EXTERNAL_STORAGE。
在最新的Android Studio和使用Java 1.8,你得到的密切語句以下編譯器錯誤:'資源泄漏:「<未分配的可關閉值> '永遠不會關閉'。任何想法如何防止這一點? – not2qubit