Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Save pdf from http inputstream to file  RSS feed

 
DN Debed
Greenhorn
Posts: 10
  • 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
Posts: 42970
73
 
Bauke Scholtz
Ranch Hand
Posts: 2458
  • 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
Sheriff
Posts: 24215
37
Chrome Eclipse IDE Mac OS X
  • 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.
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!