您的位置:首页 > 其它

把assets目录下的db文件拷贝进来

2016-04-20 10:40 239 查看
public void copyDb(String filename) {
File file = new File(getFilesDir(), filename);
if (file.exists() && file.length() > 0) {
Log.i(TAG, "DB 已经存在不需要拷贝");
} else {
try {
InputStream is = getAssets().open(filename);
FileOutputStream fos = new FileOutputStream(file);
byte[] buffer = new byte[1024];
int len = -1;
while ((len = is.read(buffer)) != -1) {
fos.write(buffer, 0, len);
}
fos.close();
is.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: