Java check if a folder exists?

Posted in :

Using java.nio.file.Files:

Path path = Paths.get("does-not-exist.txt");

if (Files.exists(path)) {
    // ...
}

You can optionally pass this method LinkOption values:

if (Files.exists(path, LinkOption.NOFOLLOW_LINKS)) {

There’s also a method notExists:

if (Files.notExists(path)) {

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *