How do you check if a file exists or not in Java?

Nguyễn Trà

New member
How do you check if a file exists or not in Java?
Answer
Check if a file exists in Java
  1. Example. import java.io.File; public class Main { public static void main(String[] args) { File file = new File(“C:/java.txt”); System.out.println(file.exists()); } }
  2. Result. The above code sample will produce the following result (if the file “java. …
  3. Example. …
  4. Output.
 

Tìm kiếm

Back
Top