Quantcast
Viewing latest article 1
Browse Latest Browse All 6

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.");
    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 latest article 1
Browse Latest Browse All 6

Trending Articles



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