/** Taken from Core Web Programming from * Prentice Hall and Sun Microsystems Press, * http://www.corewebprogramming.com/. * © 2001 Marty Hall and Larry Brown; * may be freely used or adapted. */ // Further simplified getURL method. public URL getURL() { if (url != null) { return(url); } System.out.print("Enter URL: "); System.out.flush(); BufferedReader in = new BufferedReader( new InputStreamReader(System.in)); String urlString = null; try { urlString = in.readLine(); url = new URL(urlString); } catch(MalformedURLException mue) { System.out.println(urlString + " is not valid.\n" + "Try again."); getURL(); } catch(IOException ioe) { System.out.println("IOError when reading input: " + ioe); ioe.printStackTrace(); // Can skip return(null) now } finally { return(url); } }