Lucas Eduardo
Lucas Eduardo

Reputation: 100

Delete android sqlite database file

Well I am debugging my android application on phone. There is a File Explorer in Eclipse, where I can navigate and delete some files if I want to. My application's database file is under "/data" (by default) but using the Eclipse's File Explorer I don't have access to this folder.

So my question is 'Why I don't have access'?

and

Is there a way for accessing this folder?

Thank you!

...

The way I am deleting my database file is: context.deleteDatabase(DATABASE_NAME);

Upvotes: 1

Views: 2943

Answers (4)

Junaid
Junaid

Reputation: 7860

Try this:

private void writeToSD() throws IOException {
        File f=new File("/data/data/yourPackageName/databases/DatabaseName");
        FileInputStream fis=null;
        FileOutputStream fos=null;

        try{
            fis=new FileInputStream(f);


            fos=new FileOutputStream("/mnt/sdcard/dump.db");
            while(true){
                int i=fis.read();
                if(i!=-1){
                    fos.write(i);
                }
                else{
                    break;
                }
            }
            fos.flush();

        }
        catch(Exception e){
            e.printStackTrace();

        }
        finally{
            try{
                fos.close();
                fis.close();
            }
            catch(IOException ioe){
                System.out.println(ioe);
            }
        }
    } 

Check for the exception when you call this file from within a try catch block, that will get you started. Cheers!!

Upvotes: 1

NigelK
NigelK

Reputation: 8480

Because your phone isn't rooted so Eclipse/DDMS doesn't have permission to view that folder. Which is quite correct from a security standpoint, otherwise you could edit/delete/compromise any app's data, not just your own.

Upvotes: 0

Emmanuel
Emmanuel

Reputation: 13223

So my question is 'Why I don't have access'?

You probably do not have read and write permissions to the folder

Is there a way for accessing this folder?

Yes. You need to have root access and remount the folder with read write permissions.

Upvotes: 0

Dannie
Dannie

Reputation: 2480

You need root access. Typically your device has to be rooted before you can do that.

Find out more about rooting: http://www.androidcentral.com/root

Upvotes: 0

Related Questions