You can determine if a file exists by calling the exists() method in the java.io.File class. A File instance represents a file on
your local file system and allows you to perform operations
on a file such as rename or delete. The exists() method will return
true if a file exists, and false if it does not.
==================================================================
import java.io.*;
public final class FileExists {
public static final void main(String args[]) {
int filename;
if(args.length < 1) {
System.err.println("Usage: FileExists filename1 filename2 ...");
System.exit(1);
}
for(filename = 0; filename < args.length; filename++) {
File file;
file = new File(args[filename]);
if(file.exists()) {
System.out.print(args[filename] + " exists and is ");
if(file.canWrite())
System.out.println("writable.");
else
System.out.println("not writable.");
} else
System.out.println(args[filename] + " does not exist.");
}
}
}