• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Save pdf from http inputstream to file

 
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: 42967
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
Marshal
Pie
Posts: 24208
35
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic