The Artima Developer Community
Sponsored Link

Java Answers Forum
Reading contents of a webpage

1 reply on 1 page. Most recent reply: Feb 1, 2007 2:08 AM by Rajeev Mutalik

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 1 reply on 1 page
lovelyn shillu

Posts: 1
Nickname: lovelyn
Registered: Jan, 2007

Reading contents of a webpage Posted: Jan 31, 2007 4:18 AM
Reply to this message Reply
Advertisement
Hi...
I want to connect to a website using java. I tried the following code, but Iam getting an "UnknownHostException". How to overcome this problem? Is there any other way?


import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.URLConnection;
import java.security.*;



public class URLConnectionReader
{
public static void main(String[] args) throws Exception {
URL yahoo = new URL("http:\\www.yahoo.com");
URLConnection yahooConnection = yahoo.openConnection();
BufferedReader in = new BufferedReader(new InputStreamReader(
yahooConnection.getInputStream()));
String inputLine;
while ((inputLine = in.readLine()) != null)
System.out.println(inputLine);

in.close();
}
}


Rajeev Mutalik

Posts: 57
Nickname: rajmutalik
Registered: Sep, 2002

Re: Reading contents of a webpage Posted: Feb 1, 2007 2:08 AM
Reply to this message Reply
Hi,

I tried to run the same program from my system, I am unable to connect to the outer websites (like yahoo, google etc) from my programs. But I tried to communicate to internal machines where tomcat is installed its working fine. But the only problem in ur code is "http:\\www.yahoo.com". Its incorrect, it should be "http://www.yahoo.com". Double slashes used are incorrect.

Regards,
Rajeev

Flat View: This topic has 1 reply on 1 page
Topic: Reading contents of a webpage Previous Topic   Next Topic Topic: How to get RAM size?

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use