I tried in many ways to copy my sqlite db file to my /data/data/packagename/databases folder, but I still get stuck in FileNotFoundException, triggered by the FileOutputStream object... Here's the code:
public static boolean checkCopyDb(Context c, DbHandler _db) {
try {
String destPath = "/data/data/" + c.getPackageName() + "/databases/db_sociallibraries.db";
File dbFile = new File(destPath);
if(!dbFile.exists()) {
_db.copyDb(c.getAssets().open(DB_NAME), new FileOutputStream(destPath)); // Line 44 - Throws the exception
}
return true;
}
catch (IOException e) {
e.printStackTrace();
return false;
}
}
private void copyDb(InputStream inputStream, OutputStream outputStream) throws IOException {
byte[] buffer = new byte[1024];
int length;
while((length = inputStream.read(buffer)) > 0) {
outputStream.write(buffer,0,length);
}
inputStream.close();
outputStream.close();
}
And this is the error:
02-09 01:28:46.384 24222-24222/com.test.michelemadeddu.sociallibraries W/System.err﹕ java.io.FileNotFoundException: /data/data/com.test.michelemadeddu.sociallibraries/databases/db_sociallibraries.db: open failed: ENOENT (No such file or directory) 02-09 01:28:46.384 24222-24222/com.test.michelemadeddu.sociallibraries W/System.err﹕ at libcore.io.IoBridge.open(IoBridge.java:409) 02-09 01:28:46.384 24222-24222/com.test.michelemadeddu.sociallibraries W/System.err﹕ at java.io.FileOutputStream.(FileOutputStream.java:88) 02-09 01:28:46.384 24222-24222/com.test.michelemadeddu.sociallibraries W/System.err﹕ at java.io.FileOutputStream.(FileOutputStream.java:128) 02-09 01:28:46.384 24222-24222/com.test.michelemadeddu.sociallibraries W/System.err﹕ at java.io.FileOutputStream.(FileOutputStream.java:117) 02-09 01:28:46.384 24222-24222/com.test.michelemadeddu.sociallibraries W/System.err﹕ at com.test.michelemadeddu.sociallibraries.DbHandler.checkCopyDb(DbHandler.java:44)
Am I doing something wrong? Thanks
Aucun commentaire:
Enregistrer un commentaire