Adblock breaks this site

HTML Downloader

Discussion in 'Programming General' started by Swan, Sep 28, 2007.

  1. Swan

    Swan When They Cry...
    Retired Global Moderator

    Joined:
    Jan 23, 2007
    Posts:
    4,957
    Referrals:
    0
    Sythe Gold:
    0
    Sythe's 10th Anniversary Member of the Month Winner
    HTML Downloader

    Uses BufferedReader, InputStreamReader, and URL to download and display the contents of an HTML file.

    Code:
    package htmldownloader;
    
    import java.net.*;
    import java.io.*;
    
    /**
     *
     * @author Dave
     */
    public class Main {
        public static void main(String[] args) {
            try {
                URL aURL = new URL("http://www.yahoo.com");
                BufferedReader in = new BufferedReader(new InputStreamReader(aURL.openStream()));
                String line;
                
                while((line = in.readLine()) != null)
                    System.out.println(line);
            } catch(MalformedURLException exc) {
                System.out.println("Error! Malformed URL!");
            } catch(IOException exc) {
                System.out.println("Java I/O Exception!");
            }        
        }
    }
    credits to sun and their tutorials.
     
  2. Olan14

    Olan14 Forum Addict

    Joined:
    Jan 26, 2007
    Posts:
    581
    Referrals:
    0
    Sythe Gold:
    0
    HTML Downloader

    FAIL. Mine is > yours
    Code:
     public String wget(String url) throws Throwable {     return wget(new URL(url)); }  public String wget(URL url) throws Throwable {     URLConnection urlc = url.openConnection();     DataInputStream dis = new DataInputStream(url.getInputStream());     byte[] buff = new byte[urlc.getContentLength()];     dis.readFully(buff);     return new String(buff); }
     
< Please help me to do this project. Thanks | Java "pong" game - with webstart >


 
 
Adblock breaks this site