-5

I am developing a project in that i have a module in which i need to write a Java Program to read a html page and save its HTML code of the page in a text file. Please can anyone give that above said program .......

Selva Perumal
  • 71
  • 2
  • 3
  • 6
  • 1
    Unless you show us some code we can't (shouldn't) help you. Bed time reading: [What have you tried?](http://mattgemmell.com/2008/12/08/what-have-you-tried/) – pankar Nov 01 '12 at 11:50

2 Answers2

4

have a look at http://docs.oracle.com/javase/tutorial/networking/urls/readingURL.html you dont even need an external library. Combine this with a Bufferedwriter:

import java.net.*;
import java.io.*;
import java.util.*;

public class URLReader {

    public static void main(String[] args) throws Exception {

        URL oracle = new URL("http://www.oracle.com/");
        BufferedReader in = new BufferedReader(
        new InputStreamReader(oracle.openStream()));
        BufferedWriter writer = new BufferedWriter(new FileWriter("outputfile.txt"));

        String inputLine;
        while ((inputLine = in.readLine()) != null){
            try{
                writer.write(inputLine);
            }
            catch(IOException e){
                e.printStackTrace();
                return;
            }
        }
        in.close();
        writer.close();
    }
}
Sander
  • 591
  • 6
  • 16
0

You can do this task using HTMLParser, Read about it here

Ankit
  • 3,083
  • 7
  • 35
  • 59