File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Save pdf from http inputstream to file

 
DN Debed
Greenhorn
Posts: 10
  • 0
  • Mark post as helpful
  • send pies
  • 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!
 
Ulf Dittmer
Rancher
Pie
Posts: 42966
73
 
Bauke Scholtz
Ranch Hand
Posts: 2458
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Basically you just need to write it to FileOutputStream.
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24204
34
Chrome Eclipse IDE Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
... without converting it to a String. Read into a byte[], and save the byte[] to a FileOutputStream.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic