Using java.nio.file.Files
:
Path path = ...;
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)) {
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…