HTML Downloader

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

HTML Downloader
  1. Unread #1 - Sep 28, 2007 at 3:16 AM
  2. Swan
    Joined:
    Jan 23, 2007
    Posts:
    4,957
    Referrals:
    0
    Sythe Gold:
    0
    Sythe's 10th Anniversary Member of the Month Winner

    Swan When They Cry...
    Retired Global Moderator

    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.
     
  3. Unread #2 - Oct 1, 2007 at 1:13 PM
  4. Olan14
    Joined:
    Jan 26, 2007
    Posts:
    581
    Referrals:
    0
    Sythe Gold:
    0

    Olan14 Forum Addict

    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 >

Users viewing this thread
1 guest


 
 
Adblock breaks this site