【发布时间】:2012-05-31 02:29:45
【问题描述】:
我正在尝试将数据库从资产文件夹复制到设备。此代码在模拟器和根设备上运行良好。我只是想知道它是否会在无根设备上产生任何问题,或者它会起作用。
private void StoreDatabase() {
File DbFile = new File(
"data/data/packagename/DBname.sqlite");
if (DbFile.exists()) {
System.out.println("file already exist ,No need to Create");
} else {
try {
DbFile.createNewFile();
System.out.println("File Created successfully");
InputStream is = this.getAssets().open("DBname.sqlite");
FileOutputStream fos = new FileOutputStream(DbFile);
byte[] buffer = new byte[1024];
int length = 0;
while ((length = is.read(buffer)) > 0) {
fos.write(buffer, 0, length);
}
System.out.println("File succesfully placed on sdcard");
// Close the streams
fos.flush();
fos.close();
is.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
【问题讨论】:
-
是的,您的代码 sn-p 也可以在无根设备上完美运行 :)
标签: android android-emulator android-ndk rooted-device