Omkar Amberkar
Omkar Amberkar

Reputation: 2452

How to check if .realm database already exists?

I want to check if my xyz.realm database already exists, any ideas on how tackle this?

Upvotes: 5

Views: 3280

Answers (2)

Christian Melchior
Christian Melchior

Reputation: 20126

This should work:

RealmConfiguration config = getConfig();
if (new File(config.getPath()).exists()) {
  // exists
} else {
  // don't exists
}

Upvotes: 9

jmarkstar
jmarkstar

Reputation: 1335

try this:

String defaultName = Realm.getDefaultInstance().getConfiguration().getRealmFileName();
                if("xyz.realm".equals(defaultName)){
                    //TODO
                }else{
                    //TODO
                }

Upvotes: 0

Related Questions