有关android /data/data/ [

Ronys Ronys 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
把asset下的数据库xx.db复制到/data/data/package_name/xx.db下,无法复制啊 !!什么问题 ?? 应该不用root吧? 这个目录本身是属于本应用程序的!理论上来说本应用程序是可以访问!
private SQLiteDatabase openDataBase(String path) {
Log.e("SQLite exist:", "" + new File(path).exists() + "::" + path);
// TODO Auto-generated method stub
try {
File file = new File(path);
if (!file.exists()) {// 判断数据库是否存在,若不存在执行导入操作,否则直接打开数据库
// InputStream ins = context.getResources().openRawResource(
// R.raw.ty_city);
file.createNewFile();
InputStream ins = context.getAssets().open("Chinacity.db");
FileOutputStream fos = new FileOutputStream(path);
byte[] buffer = new byte[BUFFER_SIZE];
int count = 0;
while ((count = ins.read(buffer)) > 0) {
fos.write(buffer, 0, count);
Log.e("buffer...", "" + count);
}
fos.close();
ins.close();
}
SQLiteDatabase sqLiteDatabase = context.openOrCreateDatabase(
DB_NAME, 0, null);
return sqLiteDatabase;
} catch (FileNotFoundException ffe) {
ffe.printStackTrace();
Log.e("DataBaseFile:", "file can't find");
} catch (IOException ioe) {
// TODO: handle exception
Log.e("IOException", ioe.getMessage());
ioe.printStackTrace();
}
return null;
}
报错

java.io.IOException: open failed: ENOENT (No such file or directory)//file.createNewFile();
...全文

相关推荐

评论 6
收藏 已收藏
分享
返回顶部
Ronys
Android 80,490 成员 91,375 内容