gpt4 book ai didi

java - Sqlite数据库不会复制到真实设备的sd卡中

转载 作者:行者123 更新时间:2023-12-01 15:16:48 25 4
gpt4 key购买 nike

我通过这种方法将我的数据库(sqllite)复制到SD卡:

String currentDBPath =
"\\data\\com.powergroupbd.tripmileage\\databases\\tripmileagedatabase";
String backupDBPath = "tripmileagedatabase";
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();

这在模拟器中工作正常,但当我将其安装在真实设备中时,它不会显示 SD 卡中的任何文件。我缺少什么?

最佳答案

数据库的路径从/data/data/开始。请注意,路径分隔符是正斜杠,而不是反斜杠。因此,将您的代码更改为:

String currentDBPath =
"/data/data/com.powergroupbd.tripmileage/databases/tripmileagedatabase";
String backupDBPath = "tripmileagedatabase";
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();

关于java - Sqlite数据库不会复制到真实设备的sd卡中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11495413/

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