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?
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());
You can get the path of your realm file by calling the "getPath()" method:
Here an Example:
realm.getPath()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With