public static void main(String[] args) {
        try {
            if(args.length < 2) {
                // Display usage information
                System.err.println("Usage: java URLDowloader -[h|d] <url> [<file>]");
                System.err.println("Saves the URL to a file.");
                System.err.println("If no file is given, extracts hyperlinks on url to console.");
            }
            else {
                String option = args[0];
                if(option.equals("-h")) {
                    URL url = new URL(args[1]);
                    System.out.println("Content-Type: " + url.openConnection().getContentType());
                    //Vector links = extractLinks(url);
                    //for (int n = 0; n < links.size(); n++) {
                    //  System.out.println((String) links.elementAt(n));
                    //}
                    Set<Map.Entry<String, String>> links = extractLinksWithText(url).entrySet();
                    Iterator<Map.Entry<String, String>> it = links.iterator();
                    while (it.hasNext()) {
                        Map.Entry<String, String> en = it.next();
                        String strLink = en.getKey();
                        String strText = en.getValue();
                        System.out.println(strLink + " \"" + strText + "\" ");
                    }
                }
                else if(option.equals("-d")) {
                    URL url = new URL(args[1]);
                    HttpURLConnection conn = (HttpURLConnection)url.openConnection();
                    conn.addRequestProperty("Accept", "text/xml, application/xml, application/xhtml+xml, text/html;q=0.9, text/plain;q=0.8, image/png, */*;q=0.5");
                    conn.addRequestProperty("User-Agent", "ResidentEvilCrawler/0.01b /webspider/java1.5/0.01b/518proj2");
                    conn.addRequestProperty("Connection", "Keep-Alive");
                    conn.setUseCaches(false);
                    conn.setConnectTimeout(2000);
                    conn.setReadTimeout(2000);
                    conn.connect();
                    String mimetype = conn.getContentType();

                    String filename = null;
                    if(args.length == 2) {
                        filename = args[1].substring( (args[1].lastIndexOf('/')) + 1 );
                    }
                    else if(args.length == 3) {
                        filename = args[2];
                    }
                    System.out.println("Downloading file " + filename + "...");
                    System.out.println("Content-Type: " + mimetype);
                    streamURLtoFile(conn, filename);
                    System.out.println("Download finished!");
                }
            }
        }
        catch (Exception e) {
            System.err.println("An error occured: ");
            e.printStackTrace();
            //System.err.println(e.toString());
        }
    }