我正在使用下面的代码尝试将我的数据库文件移动到我的 SD 卡。除了在 sd
下出现红线之外,我没有任何问题。有任何想法吗?
File data = Environment.getDataDirectory();
if (sd.canWrite()) {
String currentDBPath = "\\data\\application.package\\databases\\name";
String backupDBPath = "name";
File currentDB = new File(data, currentDBPath);
File backupDB = new File(sd, backupDBPath);
if (currentDB.exists()) {
FileChannel src;
try {
src = new FileInputStream(currentDB).getChannel();
FileChannel dst = new FileOutputStream(backupDB).getChannel();
try {
dst.transferFrom(src, 0, src.size());
src.close();
dst.close();
} catch (IOException e) {
e.printStackTrace();
}
} catch (FileNotFoundException e) {
e.printStackTrace();
}
最佳答案
只有创建变量的实例才能使用变量:
将其放在代码之前:
File sd = Environment.getExternalStorageDirectory();
关于java - 将我的数据库移动到 SD 卡不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13361377/