Quantcast
Channel: How to loop a try catch statement? - Stack Overflow
Browsing all 6 articles
Browse latest View live

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 Article



Answer 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 Article

Answer 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 Article

Answer 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 Article

Answer 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 Article


How 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
Browsing all 6 articles
Browse latest View live




Latest Images