Pages

Thursday, February 12, 2009

Reading all the contents of a web page in JAVA

You need to use the URL class. The sample code is stated below.

public static void main(String[] args) {
        // TODO code application logic here
        URL url;
        InputStream is = null;
        
        BufferedReader br = null;
        try {
        
        
            url = new URL("http://dsebd.org/latest_share_price_all.php");
            is = url.openStream();
            br= new BufferedReader(new InputStreamReader(is));
        } catch (MalformedURLException ex) {
            ex.printStackTrace();
        } catch (IOException ex) {
            ex.printStackTrace();
        }
        
        
        
        String tempLine;
        try {
            while((tempLine = br.readLine()) != null)
                System.out.println(tempLine);
        } catch (IOException ex) {
            ex.printStackTrace();
        }
        
        
        
        
        
    }

--
http://ifteebuet.blogspot.com/

No comments:

Post a Comment