This program will read data from a Web URL and write to Console. This program can be used to make a Custom Web browser.
import java.io.InputStream;
import java.net.URL;
import java.util.Scanner;
public class GetDataFromURL {
public static void main(String[] args) throws Exception {
URL yahoo = new URL("http://www.yahoo.com/");
InputStream inStream = yahoo.openStream();
Scanner in = new Scanner(inStream);
while (in.hasNext()) {
System.out.println(in.nextLine());
}
inStream.close();
}
}
No comments:
Post a Comment