// CSE 143, Autumn 2013 // This program uses the Downloader class to download a web page // from a URL and save it to a file on the local hard disk. // It also demonstrates the exception try/catch syntax for handling errors. import java.io.*; import java.net.*; import java.util.*; public class DownloadMain { public static void main(String[] args) { Scanner console = new Scanner(System.in); System.out.println("URL to download? "); String url = console.nextLine(); Downloader down = null; while(down == null) { try { down = new Downloader(url); } catch (MalformedURLException e) { System.out.println("Bad url. please try again "); } } System.out.println("Target file name? "); String target = console.nextLine(); try { down.download(target); } catch (IOException e) { System.out.println("File failed to download."); } } }