mport java.net.*;
import java.io.*;
class Ur {
public static void main(String[] arg) throws Exception {
URL u = new URL("http://www.whitehouse.gov/");
InputStream ins = u.openStream();
InputStreamReader isr = new InputStreamReader(ins);
BufferedReader whiteHouse = new BufferedReader(isr);
System.out.println(whiteHouse.readLine());
}
}

It shows the error..

when i changed the site to www.google .com
\Program Files\Java\jdk1.6.0_22\bin>javac Ur
ror: Class names, 'Ur', are only accepted if annotation processing is explicit
requested
error


Exception in thread "main" java.net.UnknownHostException: www.whitehouse.gov
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:177)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:366)
at java.net.Socket.connect(Socket.java:529)
at java.net.Socket.connect(Socket.java:478)
at sun.net.NetworkClient.doConnect(NetworkClient.java:163)
at sun.net.www.http.HttpClient.openServer(HttpClient.java:394)
at sun.net.www.http.HttpClient.openServer(HttpClient.java:529)
at sun.net.www.http.HttpClient.<init>(HttpClient.java:233)
at sun.net.www.http.HttpClient.New(HttpClient.java:306)
at sun.net.www.http.HttpClient.New(HttpClient.java:323)
at sun.net.www.protocol.http.HttpURLConnection.getNewHttpClient(HttpURLC
onnection.java:975)
at sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConne
ction.java:916)
at sun.net.www.protocol.http.HttpURLConnection.connect(HttpURLConnection
.java:841)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLCon
nection.java:1177)
at java.net.URL.openStream(URL.java:1010)
at Ur.main(Ur.java:6)

Recommended Answers

All 4 Replies

not sure, but check your first line.
did you copy paste the code wrong? otherwise you're missing an 'i' over there.

not sure, but check your first line.
did you copy paste the code wrong? otherwise you're missing an 'i' over there.

well consider i over there...i missed it while copying it

When I run your program I get the following output:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML+RDFa 1.0//EN" "http://www.w3.org/MarkUp/DTD/xhtml-rdfa-1.dtd">

If I change to www.google.com I get the following:

<!doctype html><html><head><meta http-equiv="content-type" content="text/html; charset=ISO-8859-1"><title>Google</title><script>window.google={kEI:"Di_sTNHhLoeMeLqA1Z0B",kEXPI:"27690,27818",kCSI:{e:"27690,27818",ei:"Di_sTNHhLoeMeLqA1Z0B",expi:"27690,27818"},ml:function(){},kHL:"en",time:function(){return(new Date).getTime()},log:function(b,d,

well u might have debug it , or in ur maching its just working fine...but i wanna ask...isn't it suppose to open the respective site...?....

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.