This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes Java in General and the fly likes Download remote jar file using java Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Download remote jar file using java " Watch "Download remote jar file using java " New topic
Author

Download remote jar file using java

shan raj
Ranch Hand

Joined: Dec 16, 2008
Posts: 42
Hi,

I want to write a java program to download remote jar file. Any one please help me to proceed further.

Btw, I tried using the below API. but when I open a jar file its not opening.

URL url = new URL("http:\\.....jar");
InputStream in=url.openStream ();

Read as byte array and save into another file using output stream.
Martijn Verburg
author
Bartender

Joined: Jun 24, 2003
Posts: 3274
    
    5

Hi there and welcome to Javaranch! Can you post a larger code example of what you have so far?


Cheers, Martijn - Blog,
Twitter, PCGen, Ikasan, My The Well-Grounded Java Developer book!,
My start-up.
shan raj
Ranch Hand

Joined: Dec 16, 2008
Posts: 42
Hi, I got the answer how to download. There was a problem in writing into the file using BufferedOutputStream. Initially I read the file and written without doing bufOut.flush(). After doing this it worked fine.

Here is the code which i tried. if any one has good alternative or effective approach of downloading file please reply me.

Martijn Verburg
author
Bartender

Joined: Jun 24, 2003
Posts: 3274
    
    5

That seems OK although I'm going to assume that in your PRD quality code you'll have the Exception handling, remove the System.out.println etc
shan raj
Ranch Hand

Joined: Dec 16, 2008
Posts: 42
Thanks Martijn.

Yeah will take care of exception handling.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Download remote jar file using java