Reputation: 2050
How do I check whether a parent directory is created or not before creating file in that directory? I can use file.exists() but it only checks if my file obj is created and not my parent directory/parent path.
Upvotes: 1
Views: 3237
Reputation: 61
public boolean exists();
that will Tests whether the file or directory denoted by this abstract pathname exists. .
String path = "URL";
File f = new File(path);
f.exists();
f.getParentFile().mkdirs(); //File with Create Dir
f.createNewFile();
Upvotes: 1
Reputation: 2844
Try that :
file.getParentFile().exists();
Will return true if the parent exists, false if not.
Upvotes: 1