How to check if a file exists in Java
Published: January 8, 2010 , Updated: May 27, 2010 , Author: mkyong
To determine whether a file is exist in your file system, use the Java IO File.exists().
package com.mkyong.io; import java.io.*; public class FileChecker { public static void main(String args[]) { File f = new File("c:\\mkyong.txt"); if(f.exists()){ System.out.println("File existed"); }else{ System.out.println("File not found!"); } } }
Any Java questions or problems? please post at this JavaNullPointer.com forum, see you there ~