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

Save an InputStream to a file  RSS feed

 
Steve Watson
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am getting an InputStream from a service (it happens to be a pdf) which I need to save to a given file. How can I do that?
 
Joe Ess
Bartender
Posts: 9406
12
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Create a FileOutputStream.
In a loop, read() from the InputStream and write() the result to the FileOutputStream until read() returns -1, then flush() and close() all streams. Plenty of examples in The Java Tutorial
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!