check folder exists java code example
Example 1: java check if directory exists
Path path = ...;
if (Files.exists(path)) {
// ...
}
Example 2: How to check if a directory exists in java
// How to check if a directory exists in java
import java.io.File;
public class CheckIfExists
{
public static void main(String[] args)
{
try
{
File fl = new File("B:/JavaExamples/CheckIfExists.txt");
fl.createNewFile();
System.out.println(fl.exists());
}
catch(Exception ex)
{
ex.printStackTrace();
}
}
}