4

I have started playing around with Berkeley DB. This one is really interesting, but I am facing one problem. While creating the Environment we create it like this -

Environment env = new Environment(new File("./bdb"), envConfig);

It initially threw an exception saying "bdb" location was not found. I created the location and it all worked.

My question is how would I set up berkeley DB to create this directory for me if it does not exist. I actually checked at the config method SetAllowCreate(boolean flag) .. but its functionality is different.

Any help would be appreciated. Thanks.

ravi
  • 1,707
  • 4
  • 29
  • 44

2 Answers2

2

You can do -

File file = new File("file path goes here");
// Either the file exists or mkdirs is successful
if (file.exists() || file.mkdirs()) {
    Environment env = new Environment(file, envConfig);
}
Vatsal Prakash
  • 558
  • 6
  • 17
don
  • 111
  • 2
  • 9
1

I actually ended up doing something like this (not sure whether it is right solution but it works)

boolean x = new file("./bdb.data").mkdir();
Environment env = new Environment(new File("./bdb"), envConfig);
ravi
  • 1,707
  • 4
  • 29
  • 44