gpt4 book ai didi

java - 将我的数据库移动到 SD 卡不起作用

转载 作者:搜寻专家 更新时间:2023-10-30 20:58:18 24 4
gpt4 key购买 nike

我正在使用下面的代码尝试将我的数据库文件移动到我的 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();
}

enter image description here

enter image description here

最佳答案

只有创建变量实例才能使用变量:

把这个放在你的代码之前:

File sd = Environment.getExternalStorageDirectory();

关于java - 将我的数据库移动到 SD 卡不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13362391/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com