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

Answer by Stalzer for How to loop a try catch statement?

$
0
0

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.");
    System.out.println("Please enter the name of the file: ");
    Scanner in = new Scanner(System.in);
    filename = new String(in.next();        
}
File file = new File(filename);
Scanner scan =  new Scanner(file);

Viewing all articles
Browse latest Browse all 6

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>