Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where can I find the default Realm Database file

I started working on the logic for my migration, using this code: https://github.com/realm/realm-java/blob/master/examples/migrationExample/src/main/java/io/realm/examples/realmmigrationexample/MigrationExampleActivity.java

And after writing the code, I get an error at this line:

String path3 = MigrationClass.copyBundledRealmFile(this, this.getResources().openRawResource(R.raw.default1), "default1");

It can't find the R.raw.default1 file, because until now, I used the default Realm like this:

Realm realm = Realm.getInstance(context);

My question is where can I get the file path for this realm file?

like image 486
rosu alin Avatar asked Dec 02 '22 17:12

rosu alin


2 Answers

Realm just uses the Context to call getFilesDir() and the default Realm is called default.realm. So in your case you should use:

String realmPath = new File(context.getFilesDir(), "default.realm").getAbsolutePath();
Realm.migrateRealmAtPath(realmPath, new CustomMigration());
like image 194
Christian Melchior Avatar answered Dec 11 '22 11:12

Christian Melchior


You can get the path of your realm file by calling the "getPath()" method:

Here an Example:

realm.getPath()
like image 20
ruclip Avatar answered Dec 11 '22 12:12

ruclip