+ 2
Java
How to text whether a file exists in Java
4 Answers
+ 5
File file = new File("file path");
if (file.exists())
//Print file exists
+ 5
//whole example
import java.io.File;
import java.io.IOException;
public class Program {
public static void main(String[] args)
throws IOException {
File file = new File("example01.txt");
file.createNewFile();
System.out.println(
file.exists() ); // true
}
}
+ 4
Use java.io.File
+ 2
You can also use java.nio.file.Files
Files.exists(Path.of("path/filename.ext"))
https://code.sololearn.com/cxM6N5i9j6mC/?ref=app