public void exportDatabse(String databaseName) {
try {
File sd = Environment.getExternalStorageDirectory();
File data = Environment.getDataDirectory();
if (sd.canWrite()) {
String currentDBPath = "//data//"+getPackageName()+"//databases//"+databaseName+"";
String backupDBPath ="//database.sql";
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();
Log.i(TAG,"coping database sucessfull");
}
}
} catch (Exception e) {
Log.i(TAG,"exception! "+ e.getMessage());
}
}
在調試sd
文件位置File sd = Environment.getExternalStorageDirectory();
是Environment.getExternalStorageDirectory返回壞值
/存儲/模擬/ 0
複製的文件是不可見在我的SDcard中。此外,我知道sd
文件的位置不正確。我怎樣才能得到database.sql文件? UPDATE
[外部存儲](https://commonsware.com/blog/2014/04/08/storage-situation-external-storage.html)不是[可移動存儲(https://開頭commonsware.com/blog/2014/04/09/storage-situation-removable-storage.html)。你有很多應該修復的重複的'/'值。並且您的副本對於大多數應用程序(和桌面操作系統)都是不可見的,除非[您獲得由'MediaStore'索引的副本](https://stackoverflow.com/questions/32789157/how-to-write-files -to-外部公共存儲功能於Android的那麼認爲,他們 - 是 - visibl)。 – CommonsWare