JAVA-MANI.BLOGSPOT.COM
Sunday, September 7, 2008
You want to create a program that reada a webpage content from the internet. The example below using the URL class to create a connection to the website. When you get the connection to a website you can read the stream and write the data to a file.

package org.kodejava.example.net;

import java.io.*;
import java.net.MalformedURLException;
import java.net.URL;

public class UrlReadPageDemo {
public static void main(String[] args) {
try {
URL url = new URL("http://www.kodejava.org");

BufferedReader reader = new BufferedReader(new InputStreamReader(url.openStream()));
BufferedWriter writer = new BufferedWriter(new FileWriter("data.html"));

String line;
while ((line = reader.readLine()) != null) {
System.out.println(line);
writer.write(line);
writer.newLine();
}

reader.close();
writer.close();
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}

0 comments:

SUBSCRIBE VIA eMAIL

Enter your email address:

Delivered by FeedBurner

Recent Posts

Firefox 3

Counter

internet companies

Live Traffic Map

Subscribe Now