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

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

$
0
0

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 File(in.next());
        Scanner scan =  new Scanner(file);
        success = true;
    } catch (FileNotFoundException e) {
        e.printStackTrace();
        System.out.println("File does not exist please try again. ");
    }
}

Viewing all articles
Browse latest Browse all 6

Trending Articles



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