GeeCON Prague 2014*
The moose likes Java in General and the fly likes how to write the bytes in OutputStream to file? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Java in General
Bookmark "how to write the bytes in OutputStream to file?" Watch "how to write the bytes in OutputStream to file?" New topic
Author

how to write the bytes in OutputStream to file?

Anthony Karta
Ranch Hand

Joined: Aug 09, 2004
Posts: 342
there is a method from API that return OutputStream, and I want to write that stream to a file? how to do that?

many thanks


SCJP 5
Edwin Dalorzo
Ranch Hand

Joined: Dec 31, 2004
Posts: 961
The problem is that once the OutputStream is created you cannot change the destiny of the bytes (i.e. memory or file).

For instance if I create an OutputStream this way:



How could I possibly make that this stream is written to a file? I daresay there is no way to do that.

However, since the OutputStream is used to write bytes, you can write those same bytes in a FileOutputStream after or before you have writen them into the returned OutputStream. In other words, you write your bytes in both streams.



Does that help?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: how to write the bytes in OutputStream to file?