wood burning stoves 2.0*
The moose likes Sockets and Internet Protocols and the fly likes Download a binary file programmatically? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Sockets and Internet Protocols
Bookmark "Download a binary file programmatically?" Watch "Download a binary file programmatically?" New topic
Author

Download a binary file programmatically?

Mark Lau
Ranch Hand

Joined: Dec 15, 2001
Posts: 120
A servlet of my application generates a binary file for cients to download.
It works fine if I just click and download it from the Web interface in a browser.
But I actually wanna get this binary file by a Java program and then parse it.
The file is in binary format, not ASCII.
How do I do this?
Michael Morris
Ranch Hand

Joined: Jan 30, 2002
Posts: 3451
Hi Gene,
You need to give us some more specifics on exactly what you want to do. Do you need to know how to connect to the servlet? Do you need to know how to download the file once connected? Do you need to know how to parse the file?


Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius - and a lot of courage - to move in the opposite direction. - Ernst F. Schumacher
Mark Lau
Ranch Hand

Joined: Dec 15, 2001
Posts: 120
Hi, Michael,
Thank you.
Actually, I don't think I need to connect to the servlet, and I know how to parse the binary file.
The only thing I wanna know is how to programmatically get that binary document in my client application.
As I have indicated in my first post, the binary document is accessible through HTTP connection. But I don't want to get it from the Web interface.
It is desirable if I can get the binary document as a stream from the Socket. But then would you guys give me a little hint?
Mark Lau
Ranch Hand

Joined: Dec 15, 2001
Posts: 120
Hi Michael, how come after i give more details, you guys keep silent?
Van Glass
Ranch Hand

Joined: Nov 18, 2000
Posts: 110
Sounds like you just need to get the content from a URL. Look at the HttpURLConnection class for details on how to do this.
Mark Mokris
Ranch Hand

Joined: May 08, 2002
Posts: 61
I have a program which does what you need to do so I grabbed some of the code. This code basically reads the home page a Amazon.com into a String.

Hope this helps.
Mark Lau
Ranch Hand

Joined: Dec 15, 2001
Posts: 120
Van, you are right. That is exactly what I want.
And Mark, thank you for your sample code. It helps, although what I wanna read is binary data.
I'll take a look at the doc for HttpURLConnection and URLConnection. Thanks.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Download a binary file programmatically?
 
Similar Threads
Binaries and SourceCode
Installing JDK on Linux (RedHat 6.2)
Upload or download binary message from URL
Test Installation
File Download issue...