Skip to main content
gamedev.net
🔒 Locked

[java] Downloading and extracting files with Java

Started by ShauwnBlue Jul 4, 2008 at 1:39 AM 6 replies 1.8k views
Original Post
ShauwnBlue
ShauwnBlue
Hello, I have a somewhat hefty task (at least for me) to work on. I need to write a program that connects to a server and downloads certain files onto my computer and unzips them. Unfortunately, I'm not sure how to start either portion of that. Does anyone know if something like this is possible? If so, could you point me in the right direction? Thanks for any help!
ssjx
ssjx
Hi, i'm not sure of your exact requirements but would this be a task better suited to a script of some kind (perl etc..) or do you have to use java?
---
Visit ssjx.co.uk for Java, Windows and Cybiko games, programs and source code!
ShauwnBlue
ShauwnBlue
Well, now that I think of it, I guess I could use a script.
I have a Java program that uses some files. However, I want the files to be up to date all the time. So every few hours, I need a program to download the newest files and unzip them.
I figured I'd do it in Java, since that's what the other program is written in.

However, I didn't really consider doing it in another scripting language.

I'm very familiar with Java, but sadly I'm not very experienced with scripting languages.

Do you have any pointers?

Thanks again!
CaptainJester
CaptainJester
If the file is available publicly, then you can just open a URLConnection to the file and download it that way. You can then use the java.util.zip package to unzip it.
"None of us learn in a vacuum; we all stand on the shoulders of giants such as Wirth and Knuth and thousands of others. Lend your shoulders to building the future!" - Michael Abrash[JavaGaming.org][The Java Tutorial][Slick][LWJGL][
ShauwnBlue
ShauwnBlue
Interesting, Jester.
I'll look into that.

Thanks a bunch for the tips. You both really helped me find a place to start.
ShauwnBlue
ShauwnBlue
I've been able to download the files... I got that part working.
I'm unable to unzip them though.

Apparantly the normal ZipFile classes aren't of use for me. The archives I need to extract are actually .tgz files.

Anybody have pointers on how to extract the .tar files from the .tgz files?

Thanks again for any help.

*EDIT* I've got it to work now.
Thanks to everyone for helping me.

[Edited by - ShauwnBlue on July 7, 2008 6:15:43 PM]
5MinuteGaming
5MinuteGaming
I would use the command line to unzip the files once you have them downloaded. You can do this from your Java program by using Runtime.getRuntime().exec(unzipCommandString);

Make sure you have the absolute path of the zip file and destination folder it will make things more robust than attempting to navigate the runtime to the right directory. I would use the unix command gunzip if you're working on a unix based operating system.

Here's just a quick link I found for the gunzip command GZIP

If your on a windows machine then I would use winrar or winzip.

Heres a link of how to use winrar through the command prompt on a windows machine.
http://www.respower.com/page_tutorial_unrar


Good Luck hope this helps.
ShauwnBlue
ShauwnBlue
Thanks very much for taking the time to write up that response with links and everything. I appreciate it.
It was very helpful as well.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.