+ 2

Java

How to text whether a file exists in Java

27th Apr 2022, 7:56 AM
Godwin Kofi Alormenu
Godwin Kofi Alormenu - avatar
4 Answers
+ 5
File file = new File("file path"); if (file.exists()) //Print file exists
27th Apr 2022, 8:16 AM
AĶ¢J
AĶ¢J - avatar
+ 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 } }
27th Apr 2022, 9:02 AM
zemiak
+ 4
Use java.io.File
27th Apr 2022, 8:01 AM
Wakil Ah Hamidi
Wakil Ah Hamidi - avatar
+ 2
You can also use java.nio.file.Files Files.exists(Path.of("path/filename.ext")) https://code.sololearn.com/cxM6N5i9j6mC/?ref=app
29th Apr 2022, 4:14 AM
Tibor Santa
Tibor Santa - avatar