Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Access a file on a webserver port80 (socket?)

Status
Not open for further replies.

lukelukeluke

Technical User
Dec 23, 2003
117
CH
Hi there,

I wanted to access a file on a webserver in my java application. For example the file: has the content:
Hello World,\nJava is cool!
inside. Now, can I access this site from my JAVA application on an easy way? Do i need a socket for this? I have only basic knowledge in java... - Is there a tutorial for something like this somewhere (didnt find anything specific for this on google...)?
Well what i want to do is change the content of my php file sometimes and the java application will always be actual...

Thanks for your help.
Greetings, Lucas

Webmaster of knowledgebase for IT knowledge.
 
You should use the classes in java.net like HttpURLConnection and URL.

EG :

URL url = new URL("HttpURLConnection huc = (HttpURLConnection)url.openConnection();

You may then read the data by using the IO streams in that class.



--------------------------------------------------
Free Database Connection Pooling Software
 
Hi sedj. Thanks alot for your time!
About this: "You may then read the data by using the IO streams in that class": What does that mean?

I'm a java programmer with basic knowledge. I know strings, variables, arrays, loops but not many more. Is tehre a way i can get the content of the file inside a String?

Thanks!
Greetings, Lucas

Webmaster of knowledgebase for IT knowledge.
 
In the HttpURLConnection there are two methods that give acess to the IO streams of the socket opened by the HttpURLConnection - getInputStream() and getOutputStream(). You should use these to read your data.

The java.io package is a core package, and if you want to learn Java, you should get used to them before trying any slightly more advanced stuff like downloading web pages - perhaps read throught this tutorial .

--------------------------------------------------
Free Database Connection Pooling Software
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top