• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Save pdf from http inputstream to file

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, i'd like to ask how can I save the pdf file being sent from an HttpUrlConnection to a file?

Im using an HttpURLConnection to call a report from ms sql server report server. This should return a pdf file.

Then upon checking the getInputStream(), and writing the stream as string, I can tell that the contents are the pdf file itself(although it prints out probably hex values).

Normally, if it is run in a web application, it displays the pdf automatically.

But im running the code in a desktop environment (probably command line only). So what i need is to get the inputstream of the httpurlconnection, and save it to its PDF file.

Other approach is welcomed also... thank you!
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This should help: http://www.ibiblio.org/java/books/jnp3/examples/15/BinarySaver.java
 
Ranch Hand
Posts: 2458
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Basically you just need to write it to FileOutputStream.
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
... without converting it to a String. Read into a byte[], and save the byte[] to a FileOutputStream.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic