SQLite Database Does Not Display in Explorer

My application has a SQLite database. When I go on to check whether the database is created or not in the File Explorer, there is no database file in the data folder. It did not even appear with the adb shell command. Does this mean that the database has not yet been created? Any suggestions on how to solve this?

+4
source share
1 answer

If you are using an actual device, you will not be able to see or access it from the outside unless you connect your phone.

If you are using an emulator, the DDMS view will allow you to go to it and pull it out of there.

Or you may have a problem creating your database. Without seeing the code, we cannot say.

EDIT

If you want to delete a file from a real device, you will need to implement a method for copying it from your data directory to the place where you have access (for example, an SD card). This would do the trick:

 public void backup() { try { File sdcard = Environment.getExternalStorageDirectory(); File outputFile = new File(sdcard, "YourDB.bak"); if (!outputFile.exists()) outputFile.createNewFile(); File data = Environment.getDataDirectory(); File inputFile = new File(data, "data/your.package.name/databases/yourDB"); InputStream input = new FileInputStream(inputFile); OutputStream output = new FileOutputStream(outputFile); byte[] buffer = new byte[1024]; int length; while ((length = input.read(buffer)) > 0) { output.write(buffer, 0, length); } output.flush(); output.close(); input.close(); } catch (IOException e) { e.printStackTrace(); throw new Error("Copying Failed"); } } 
+6
source

All Articles