-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 .......

1
  • 1
    Unless you show us some code we can't (shouldn't) help you. Bed time reading: What have you tried? Commented Nov 1, 2012 at 11:50

2 Answers 2

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();
    }
}
Sign up to request clarification or add additional context in comments.

Comments

0

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.