当然可以,这样的工作对我来说没有root权限:
File Db = new File("/data/data/your.package/databases/yourdatabasename");
Date d = new Date();
File file = new File("your_destination.db");
file.setWritable(true);
copyFile(new FileInputStream(Db), new FileOutputStream(file));
复制文件是这样的功能,并在两个方向上DB->文件和文件 - >工作DB:
public static void copyFile(FileInputStream fromFile, FileOutputStream toFile) throws IOException {
FileChannel fromChannel = null;
FileChannel toChannel = null;
try {
fromChannel = fromFile.getChannel();
toChannel = toFile.getChannel();
fromChannel.transferTo(0, fromChannel.size(), toChannel);
} finally {
try {
if (fromChannel != null) {
fromChannel.close();
}
} finally {
if (toChannel != null) {
toChannel.close();
}
}
}
}
以编程方式在SD文件夹上创建sqlite,那么您将不需要root用户的设备。如果你已经创建了一个sqlite数据库,那么如果你有有限的表,那么创建一个代码,它将读取这些表中的值,并在SD卡的另一个位置创建它们的副本。 – Kedarnath
@Kedarnath谢谢你的评论,你知道如何在指定位置创建数据库吗?目前我的数据库类正在扩展SQLiteOpenHelper – user3524019
http://stackoverflow.com/a/7227851/3330969 – Kedarnath