android资产目录,android – 从非目录设备中的资产文件夹复制数据库
我正在嘗試從資產(chǎn)文件夾將數(shù)據(jù)庫復(fù)制到設(shè)備.此代碼在模擬器和根設(shè)備上正常工作.我只是想知道是否在無人看管的設(shè)備上創(chuàng)建任何問題,否則它會相同.
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();
}
}
}
總結(jié)
以上是生活随笔為你收集整理的android资产目录,android – 从非目录设备中的资产文件夹复制数据库的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: java 静态块初始化_简单了解java
- 下一篇: python 自动上报json信息_py