This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
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


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
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?
 
Similar Threads
how to create ontology
OutputStream
writing file to OutputStream
Receiving a stream from a jsp
A question regarding saving jpgs into text files.