アセットフォルダからDBにコピーしようとしています。このコードは、エミュレータとルートデバイスで正常に動作しています。私はちょうどそれがunrootedデバイス上の任意の問題を作成するか、それが同じ動作するか知りたいです。アロケートされていないデバイスのassetsフォルダからデータベースをコピーします。
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();
}
}
}
はい、あなたのコードスニペットは、あまりにも無根のデバイス上で完璧に動作します:) –