Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Download a binary file programmatically?

 
Mark Lau
Ranch Hand
Posts: 120
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3451
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Mark Lau
Ranch Hand
Posts: 120
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 120
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Michael, how come after i give more details, you guys keep silent?
 
Van Glass
Ranch Hand
Posts: 110
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 61
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 120
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic