aspose file tools*
The moose likes I/O and Streams and the fly likes Save pdf from http inputstream to file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "Save pdf from http inputstream to file" Watch "Save pdf from http inputstream to file" New topic
Author

Save pdf from http inputstream to file

DN Debed
Greenhorn

Joined: Nov 03, 2008
Posts: 10
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
Marshal

Joined: Mar 22, 2005
Posts: 41809
    
  62
This should help: http://www.ibiblio.org/java/books/jnp3/examples/15/BinarySaver.java


Ping & DNS - my free Android networking tools app
Bauke Scholtz
Ranch Hand

Joined: Oct 08, 2006
Posts: 2458
Basically you just need to write it to FileOutputStream.
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24184
    
  34

... without converting it to a String. Read into a byte[], and save the byte[] to a FileOutputStream.


[Jess in Action][AskingGoodQuestions]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Save pdf from http inputstream to file