User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the Java section within the Software Development category of DaniWeb, a massive community of 427,488 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,418 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Java advertiser: Lunarpages Java Web Hosting
Views: 2622 | Replies: 7
Reply
Join Date: Sep 2006
Posts: 65
Reputation: rpjanaka is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
rpjanaka rpjanaka is offline Offline
Junior Poster in Training

Question Access an URL using java program

  #1  
Sep 21st, 2006
hi im janaka priyadarshana,

I want to write a program to access a given URL. dont need to show it on a browser. only want to get the html tags and write it on a text file.

serch on internet for this purpos, but unable to find any idea.

please if you can help me, give me an idea to do this using java


thank you.
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Jul 2006
Location: Glenelg, Adelaide
Posts: 229
Reputation: DavidRyan is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 11
DavidRyan's Avatar
DavidRyan DavidRyan is offline Offline
Posting Whiz in Training

Re: Access an URL using java program

  #2  
Sep 21st, 2006
Use this page.
Java API
Please anyone, correct me if I am wrong. It is the best way for me to learn.
Reply With Quote  
Join Date: Feb 2006
Posts: 1,460
Reputation: masijade is just really nice masijade is just really nice masijade is just really nice masijade is just really nice masijade is just really nice 
Rep Power: 9
Solved Threads: 131
masijade's Avatar
masijade masijade is online now Online
Nearly a Posting Virtuoso

Re: Access an URL using java program

  #3  
Sep 21st, 2006
See Above link. The class you want is probably HttpUrlConnection.
Java Programmer and Sun Systems Administrator

----------------------------------------------

Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
Reply With Quote  
Join Date: Jul 2006
Location: Glenelg, Adelaide
Posts: 229
Reputation: DavidRyan is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 11
DavidRyan's Avatar
DavidRyan DavidRyan is offline Offline
Posting Whiz in Training

Re: Access an URL using java program

  #4  
Sep 21st, 2006
By the way, I noticed you didn't even bother to google
java access a url
Yeah you really "...serch on internet for this purpos, but unable to find any idea..."

And use a spell checker, even if only to prevent putting off people who could help you.
Last edited by DavidRyan : Sep 21st, 2006 at 3:23 am.
Please anyone, correct me if I am wrong. It is the best way for me to learn.
Reply With Quote  
Join Date: Sep 2006
Posts: 65
Reputation: rpjanaka is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
rpjanaka rpjanaka is offline Offline
Junior Poster in Training

Re: Access an URL using java program

  #5  
Sep 21st, 2006
janaka priyadarshana


i tried to execute the following program that was got from sun java tutorials. but it gave some execeptios as follow. unable to find why.

please help me to do that



import java.net.*;
import java.io.*;

public class MyURLConnection {
public static void main(String[] args) throws Exception {
URL yahoo = new URL("http://www.google.com/");
URLConnection yc = yahoo.openConnection();
BufferedReader in = new BufferedReader(
new InputStreamReader(
yc.getInputStream()));
String inputLine;

while ((inputLine = in.readLine()) != null)
System.out.println(inputLine);
in.close();
}
}





the given exception is as follw.


Exception in thread "main" java.net.ConnectException: Connection timed out: connect
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:333)
at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:195)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:182)
at java.net.Socket.connect(Socket.java:507)
at java.net.Socket.connect(Socket.java:457)
at sun.net.NetworkClient.doConnect(NetworkClient.java:157)
at sun.net.http://www.http.HttpClient.openServe...lient.java:365)
at sun.net.http://www.http.HttpClient.openServe...lient.java:477)
at sun.net.www.http.HttpClient.<init>(HttpClient.java:214)
at sun.net.www.http.HttpClient.New(HttpClient.java:287)
at sun.net.www.http.HttpClient.New(HttpClient.java:299)
at sun.net.http://www.protocol.http.HttpURLConn...ction.java:792)
at sun.net.http://www.protocol.http.HttpURLConn...ction.java:744)
at sun.net.http://www.protocol.http.HttpURLConn...ction.java:669)
at sun.net.http://www.protocol.http.HttpURLConn...ction.java:913)
at MyURLConnection.main(MyURLConnection.java:9)

Reply With Quote  
Join Date: Nov 2004
Location: Netherlands
Posts: 5,752
Reputation: jwenting is a jewel in the rough jwenting is a jewel in the rough jwenting is a jewel in the rough jwenting is a jewel in the rough 
Rep Power: 18
Solved Threads: 199
Colleague
jwenting's Avatar
jwenting jwenting is offline Offline
duckman

Re: Access an URL using java program

  #6  
Sep 21st, 2006
Google refuses to be connected with Yahoo I guess
As people are clearly allowed to attack me but I'm not allowed to defend myself, I no longer post to this site.
Reply With Quote  
Join Date: Jul 2006
Location: Glenelg, Adelaide
Posts: 229
Reputation: DavidRyan is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 11
DavidRyan's Avatar
DavidRyan DavidRyan is offline Offline
Posting Whiz in Training

Re: Access an URL using java program

  #7  
Sep 21st, 2006
Did you have an open connection at the time? Also, your firewall may be blocking those ports.
Please anyone, correct me if I am wrong. It is the best way for me to learn.
Reply With Quote  
Join Date: Aug 2004
Location: North Carolina
Posts: 27
Reputation: Banderson is an unknown quantity at this point 
Rep Power: 5
Solved Threads: 2
Banderson's Avatar
Banderson Banderson is offline Offline
Light Poster

Re: Access an URL using java program

  #8  
Sep 24th, 2006
There is nothing wrong with this code. Read the first line of the exception:

Exception in thread "main" java.net.ConnectException: Connection timed out: connect

Your connection timed out. That's all.

http://www.ecst.csuchico.edu/~tlopez...Exception.html
Last edited by Banderson : Sep 24th, 2006 at 7:37 pm. Reason: Added URL
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb Java Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the Java Forum

All times are GMT -4. The time now is 6:55 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC