【发布时间】:2021-06-18 07:48:06
【问题描述】:
我正在将 SQLite 数据库从 assets 文件夹复制到 android 应用程序。我正在使用下面提到的代码。它工作正常,我正在顺利地完成我的代码。突然,它停止将数据库复制到 Android 应用程序。
public class PreCreateDB {
public static void copyDB (Context context) {
try {
String destPath = "/data/data/"+ context.getPackageName()+ "/databases";
File f = new File(destPath);
if (!f.exists()) {
f.mkdir();
rawCopy(context.getAssets().open("dbname.db"), new FileOutputStream(destPath + "/dbname.db"));
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
public static void rawCopy(InputStream inputStream, OutputStream outputStream) throws IOException{
byte[] buffer = new byte[1024];
int length;
while ((length=inputStream.read(buffer)) > 0) {
outputStream.write(buffer, 0, length);
}
inputStream.close();
outputStream.close();
}
}
我在设备文件资源管理器中找到了 db,我在其中看到了以下几行(不是整个表)。请帮忙
SQLite format 3 @ .�
� � W--ctableandroid_metadataandroid_metadataCREATE TABLE android_metadata (locale TEXT)
� � en_IN
【问题讨论】: