Check if file or directory exists in Java

Check if file exists:

File f = new File("/path/to/filename");
if(f.exists()){
    ..
}

Check if directory exists:

File f = new File("/path/to/folder/");
if(f.exists() && f.isDirectory()){
    ..
}
Categories: Java Tags: , , , , ,
%d bloggers like this: