Java web-file stream?

The geek forum. PHP, Perl, HTML, hardware questions etc.. it's all in here. Got a techie question? We'll sort you out. Ask your questions or post a link to your own site here!

Java web-file stream?

Postby Slater » Sun Nov 16, 2008 11:24 pm

Hey, I just had a question... for my term project, I have to write a program (using either Java or JScript) that, given an arbitrary URL to an HTML file, saves the file as well as all the media objects embedded within the page (pictures, audio, and videos in particular).

Having never done any real web programming before, I'm a little curious on how to start with this. Does Java have an I/O stream that lets me grab files off the internet if I pass it a random URL? If so, I'd be very interested in that!
Image
User avatar
Slater
 
Posts: 2671
Joined: Sat May 22, 2004 10:00 am
Location: Pacifica, Caliphornia

Postby Warrior4Christ » Mon Nov 17, 2008 12:14 am

You can download files over HTTP by using a TCP socket.
Use a Socket object (and give it the host name and port number - might be 80 for standard www). Then use getInputStream and getOutputStream methods. You'll send down HTTP requests for files in the input stream, and get the file contents in the output stream.
Use the GET command:
http://en.wikipedia.org/wiki/HyperText_Transfer_Protocol

Also, before you do anything, try it with telnet. As in "telnet [hostname:port]", then type HTTP commands that your program would use, to see the expected output.
Everywhere like such as, and MOES.

"Expect great things from God; attempt great things for God." - William Carey
User avatar
Warrior4Christ
 
Posts: 2045
Joined: Sat Aug 20, 2005 8:10 pm
Location: Carefully place an additional prawn on the barbecue


Return to Computing and Links

Who is online

Users browsing this forum: No registered users and 106 guests