How to check if a directory exists?

So you can check the existence of a directory or just the existence of a file?

File file = new File(filepath); if (file.exists()) { ... } 
  • If the directory already exists, it will not be created. And Files.exists (path) - GenCloud

1 answer 1

You can check the existence of a folder or file as follows:

 import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; ... Path path = Paths.get("E:\\NecessaryFolder"); if (Files.exists(path)) { // действия, если папка существует } ... 

Read more about this here: docs.oracle.com .
Similar question: How to check if a folder exists .
And also here: click .