1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
/* Determine if file or directory exists This Java example shows how to determine if a particular file or directory exists in the filesystem using exists method of Java File class. */ import java.io.*; public class DetermineIfFileExists { public static void main(String[] args) { //create file object File file = new File("C://FileIO/ExistsDemo.txt"); /* * To determine whether specified file or directory exists, use * boolean exists() method of Java File class. * * This method returns true if a particular file or directory exists * at specified path in the filesystem, false otherwise. */ boolean blnExists = file.exists(); System.out.println("Does file " + file.getPath() + " exist ?: " + blnExists); } } /* Output would be Does file C:FileIOExistsDemo.txt exist ?: true */ |
Add Comment