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)) {