File downloader?
I am working on porting an application I made to Java. I am new to Java and need some help. I need a way to download files from a website (ex. http://arcade.x3nopro.com/x3no_arcade.zip) and save them locally. I need it to be able to download files without asking the user because most of the main application files are downloaded on startup. Can anyone help me do this?
[376 byte] By [
X3noa] at [2007-11-27 10:19:49]

Networking and I/O do not require User interaction unless your application or OS security requires it.
Anyway, this is very easy to do. I'll send you off to the tutorials first, but after that you can modify the code below, see http://java.sun.com/docs/books/tutorial/networking/urls/readingURL.html:
URL file = new URL("http://arcade.x3nopro.com/x3no_arcade.zip");
BufferedReader in = new BufferedReader(
new InputStreamReader(
file.openStream()));
String inputLine;
while ((inputLine = in.readLine()) != null)
System.out.println(inputLine);
in.close();
* Note the code above was taken directly from the Sun tutorial then modified. You'll want to change from using a BufferedReader to use a FileInputStream AFTER reading the headers. *
If he's using URL.openStream, (i) there won't be any headers, and (ii) he won't be able to use a FileInputStream. And 'file' is a very strange name for a URL variable.
He should use a BufferedInputStream and a FileOutputStream.
ejpa at 2007-7-28 16:59:58 >

> If he's using URL.openStream, (i) there won't
> be any headers, and (ii) he won't be able to
> use a FileInputStream. And 'file' is a very strange
> name for a URL variable.
>
> He should use a BufferedInputStream and a
> FileOutputStream.
So how would I do that?
X3noa at 2007-7-28 16:59:58 >
