How to check if file exists?
Use File class and exists() method
If file or directory exists it will return true otherwise false
import java.io.File; public class ExistsFile { public static void main(String[] args) { File file = new File("readme.txt"); boolean result = file.exists(); if( result == true ) System.out.println( "File exists" ); else System.out.println( "File doesn't exists" ); } }
No comments:
Post a Comment