Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / January 2008

Tip: Looking for answers? Try searching our database.

Downloading a binary file

Thread view: 
bruce_phipps@my-deja.com - 07 Jan 2008 09:38 GMT
I want to download a 4 meg binary file from a Linux server to my
standalone Java client program.
An example I have seen first creates a URL object, then creates an
Input Stream, then downloads data via a data buffer using read() and
write():

URL url = new URL("http://test.com/files/myfile");
InputStream in = url.openStream();
byte[] buf = new byte[4*1024]; //4k buffer
int bytesRead;
while ((bytesRead=in.read(buf)) != -1) {
out.write(buf,0,bytesRead);
}

Are there any simpler methods to do this?

Thanks
Bruce
Gordon Beaton - 07 Jan 2008 09:42 GMT
> I want to download a 4 meg binary file from a Linux server to my
> standalone Java client program.
[...]
> Are there any simpler methods to do this?

What part of the example do you think is too complex?

Perhaps this is easier for you:

 Runtime.getRuntime().exec("curl -O http://test.com/files/myfile");

Or maybe just:

 dwim("http://test.com/files/myfile");

/gordon

--
bruce_phipps@my-deja.com - 07 Jan 2008 11:48 GMT
> > I want to download a 4 meg binary file from a Linux server to my
> > standalone Java client program.
[quoted text clipped - 14 lines]
>
> --

Thanks. curl is not available on the Solaris client I am using.
Bruce
Arne Vajhøj - 08 Jan 2008 00:36 GMT
>> I want to download a 4 meg binary file from a Linux server to my
>> standalone Java client program.
[quoted text clipped - 6 lines]
>
>   Runtime.getRuntime().exec("curl -O http://test.com/files/myfile");

That is simple per poster request, but I do not consider
it a recommendable solution.

Arne
Gordon Beaton - 08 Jan 2008 07:43 GMT
> That is simple per poster request, but I do not consider
> it a recommendable solution.

That suggestion, just like the one that you didn't quote, was not a
serious one. I'm still interested to hear what the OP thinks was too
complex in the example he posted though.

/gordon

--
Roedy Green - 07 Jan 2008 10:32 GMT
On Mon, 7 Jan 2008 01:38:22 -0800 (PST), "bruce_phipps@my-deja.com"
<bruce_phipps@my-deja.com> wrote, quoted or indirectly quoted someone
who said :

>I want to download a 4 meg binary file from a Linux server to my
>standalone Java client program.

See the download method in the FileTransfer class.

http://mindprod.com/products1.html#FILETRANSFER
Signature

Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com

Arne Vajhøj - 08 Jan 2008 00:33 GMT
> I want to download a 4 meg binary file from a Linux server to my
> standalone Java client program.
[quoted text clipped - 11 lines]
>
> Are there any simpler methods to do this?

No. That is the method.

(it is possible to make it more advanced and check HTTP header etc.)

Arne
Chase Preuninger - 08 Jan 2008 00:59 GMT
It may be simpler without the buffer, and I think you can also use the
read bytes method, which would read the data into an array of bytes.


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.