-2

i am trying to export the SQLite database from my application so that i could do a Export/Import feature for my application.

I am using the example from here & here for attempting to export the SQLite database (/data/data/com.example.worldcountriesbooks/databases/group.db) out of the Android device (Samsung Galaxy Note), Android 4.0.3 but i keep getting this error

12-14 00:56:33.722: I/Failed(14850): java.io.FileNotFoundException: /data/data/com.example.worldcountriesbooks/databases/group.db: open failed: ENOENT (No such file or directory)

I have also attempted to add the WRITE_EXTERNAL_STORAGE & WRITE_MEDIA_STORAGE into the manifest file but it doesn't work. I am able to browse to the actual file on my Android device as it is rooted but i can't read it with my application. Any idea why?

Sample code:

    try {
        File sd = Environment.getExternalStorageDirectory();
        File data = Environment.getDataDirectory();

        if (sd.canWrite()) {
            String currentDBPath = "//data//com.example.worldcountriesbooks/databases//group.db";
            String backupDBPath = "//mnt//sdcard//database.db";
            File currentDB = new File(data, currentDBPath);
            File backupDB = new File(sd, backupDBPath);

            FileChannel src = new FileInputStream(currentDB).getChannel();
            FileChannel dst = new FileOutputStream(backupDB).getChannel();
            dst.transferFrom(src, 0, src.size());
            src.close();
            dst.close();
            Toast.makeText(getBaseContext(), backupDB.toString(),
                    Toast.LENGTH_LONG).show();

        }
    } catch (Exception e) {

        Toast.makeText(getBaseContext(), e.toString(), Toast.LENGTH_LONG)
                .show();
    }
Community
  • 1
  • 1
dythe
  • 840
  • 5
  • 21
  • 45

1 Answers1

1

If the file is in internal memory, Your app can read only from a special folder in internal memory. The path to that folder is returned by:

getFilesDir().getAbsolutePath()

In your case it would be something like:

String path= this.getFilesDir().getAbsolutePath() + File.separator + "databases" + File.separator + "group.db";

you can read it with openFileInput().

More info:

http://developer.android.com/guide/topics/data/data-storage.html#filesInternal

Anup Cowkur
  • 20,443
  • 6
  • 51
  • 84
  • so there's no way i can copy out the sqlite database from my application? – dythe Dec 13 '12 at 17:10
  • yes, i am already trying to write it to my sd card, but it can't even open the `/data/data` internal database to write to the sd card – dythe Dec 13 '12 at 17:16