File directory = cw.getDir("media", Context.MODE_PRIVATE);
//directory.mkdirs();
File backupDB = new File(directory, backupname);
我也试过
File directory = new File(Environment.getExternalStorageDirectory()+File.separator+"images");
和
File backupDB = new File(directory, backupname);
,没有运气文件,这是全方法
public String backUpDatabase(String backupname){
try {
File directory = new File(String.valueOf(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS)));
File currentDB = new File(DBlocation);
File folder = new File("/sdcard/exports/Database_Backups/");
File backupDB = new File(directory, backupname);
if (!(folder.exists() && folder.isDirectory())) {
folder.mkdirs();
}
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();
}
else{
return "didnt work";
}
} catch (Exception e) {
return "didnt work";
}
return backupname.toString();
}
我已经使用权限是。
我只想将数据库文件备份到可访问的文件,然后我可以在手机/计算机上看到它。
2017-06-27
Jube
+1
您可以检查这个答案https://stackoverflow.com/questions/8330276/write-a-file-in-external-storage-in-android它可以帮助你.. –