Check for file

I'm trying to ask the user for a file to use. If the file is found then the program continues, but if the file is not found the user is asked to enter the filename again and again until it's found. I assume I could do it with a loop, but I'm unsure of the condition to test for the file not found.

BufferedReader stdin = new BufferedReader(new InputStreamReader

System.in));

String filename = null;

do{

System.out.print("Please enter filename: ");

filename = stdin.readLine();

}while (file is not found?)

Any ideas?

[573 byte] By [bazusa] at [2007-9-30 22:10:47]
# 1
RTFA, File class.
CeciNEstPasUnProgrammeur at 2007-7-7 11:23:53 > top of Java-index,Security,Event Handling...
# 2

Use a File object (perhaps a 'global' variable), and each time a file name is input, check if it exists.

If it does, set your global File object to be a reference to the file-name that was input, and get on with the rest of the program...

kind regards,

lutha

PS 'A' in Rene's post above stands for 'API' -- the API documentation, in case you didn't know.

Learn how to use it; it is most important...

lutha_brother at 2007-7-7 11:23:53 > top of Java-index,Security,Event Handling...
# 3
There is an exists() method in File - indeed RTFA
javajugs at 2007-7-7 11:23:53 > top of Java-index,Security,Event Handling...