I want to know how can we read the texts that are in a webpage and store it in a file in our local disk. i want to read the text line by line and store it in the text file in my local disk. can anyone help me???

ok!!! i m new to java.. can i do this using net beans? i created a sample html page with some text in that. shud i write the codin in a java class or servlet? what package to import?

You can write it in any editor that you please. Read the links and check the API docs for those classes that you do not know.

try {
        // Create a URL for the desired page
        URL url = new URL("http://localhost:8084/WebAppliccation2/sample.html");

        // Read all the text returned by the server
        BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));
        String str;
        while ((str = in.readLine()) != null) {

}
in.close();

wat shud i write in the while loop??

Edited 3 Years Ago by Dani: Formatting fixed

try {
        // Create a URL for the desired page
        URL url = new URL("http://localhost:8084/WebAppliccation2/sample.html");

        // Read all the text returned by the server
        BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));
        String str;
        while ((str = in.readLine()) != null) {

}
in.close();

wat shud i write in the while loop??

Edited 3 Years Ago by Dani: Formatting fixed

I already provided links above that cover the major steps involved. If you need more general links on Java, look through the "Read Me: Starting Java" thread that is stickied at the top of the forum.

Comments
You have a lot of patience.

Hi Guys,
I have one doubt in above discussion,If we do like which you discussed above,We can get webpage source code only,If we want text means content ,then what we do guys.Any suggestion?

This article has been dead for over six months. Start a new discussion instead.