Sign in to follow this  

[java] Downloading and extracting files with Java

This topic is 3479 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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!

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
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!

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Interesting, Jester.
I'll look into that.

Thanks a bunch for the tips. You both really helped me find a place to start.

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

This topic is 3479 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this