Page 1 of 1

Java web-file stream?

PostPosted: Sun Nov 16, 2008 11:24 pm
by Slater
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!

PostPosted: Mon Nov 17, 2008 12:14 am
by Warrior4Christ
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.