java - android sqlite delete database in package -
i used following code
string destdir = "/data/data/" + getpackagename() + "/databases/"; string destpath = destdir + "jobs"; file f = new file(destpath); if (!f.exists()) { //---make sure directory exists--- file directory = new file(destdir); directory.mkdirs(); //---copy db assets folder // databases folder--- try { copydb(getbasecontext().getassets().open("jobs"), new fileoutputstream(destpath)); } catch (filenotfoundexception e) { e.printstacktrace(); } catch (ioexception e) { e.printstacktrace(); } } public void copydb(inputstream inputstream, outputstream outputstream) throws ioexception { //---copy 1k bytes @ time--- byte[] buffer = new byte[1024]; int length; while ((length = inputstream.read(buffer)) > 0) { outputstream.write(buffer, 0, length); } inputstream.close(); outputstream.close(); }
this copies database assets folder data/data database folder , can use if not there.
i need able delete file in package , copy file assets every time app runs.
i update data in database copying new database assets folder each time , unless un-install app , re install new data not added.
i want load database folder on device user has update replace file , app reads new file that's later.
so... remove line:
if (!f.exists()) {
and corresponding closing bracket (})
this copy db always, when run app.
(it implicitly deletes file you, if found)
Comments
Post a Comment