Answer by Stalzer for How to loop a try catch statement?
Check if the file exists using the API. String filename = ""; while(!(new File(filename)).exists()) { if(!filename.equals("")) System.out.println("This file does not exist.");...
View ArticleAnswer by andand for How to loop a try catch statement?
Try something like this: boolean success = false; while (!success) { try { System.out.println("Please enter the name of the file: "); Scanner in = new Scanner(System.in); File file = new...
View ArticleAnswer by Stephen C for How to loop a try catch statement?
If you want to retry after a failure, you need to put that code inside a loop; e.g. something like this: boolean done = false; while (!done) { try { ... done = true; } catch (...) { } } (A do-while is...
View ArticleAnswer by James Montagne for How to loop a try catch statement?
You can simply wrap it in a loop: while(...){ try{ } catch(Exception e) { } } However, catching every exception and just assuming that it is due to the file not existing is probably not the best way of...
View ArticleAnswer by squiguy for How to loop a try catch statement?
Instead of using a try catch block, try a do while loop checking if the file exists. do { } while ( !file.exists() ); This method is in java.io.File
View ArticleHow to loop a try catch statement?
How do you loop a try/catch statement? I'm making a program that is reading in a file using a Scanner and it's reading it from the keyboard. So what I want is if the file does not exist, the program...
View Article