tags:

views:

46

answers:

1

When using

file.createNewFile();

I get the following exception

java.io.IOException: Parent directory of file does not exist: /.../pkg/databases/mydb

I am wondering is there a createNewFile that creates the missing parent directories?

+5  A: 

Have you tried this?

file.getParentFile().mkdirs();
file.createNewFile();

I don't know of a single method call that will do this, but it's pretty easy as two statements.

Jon Skeet