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.

which links??? the one u gave with the first reply??

which links??? the one u gave with the first reply??

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

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

please suggest me some books for reference

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.

commented: You have a lot of patience. +3

check web-harvest. very useful for scrapping web pages

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?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.