I want to dynamically generate plaintext data and expose it in some generic way so it can be, for example saved to file or sent over the network.
I am not writing to a file immediately because I don't know whether my data is going to be used in file form.
Is there any easy way to convert OutputStream (PrintStream to be exact) to a plaintext file?
Of course. Just use the PrintStream constructor which takes a File object and then the PrintStream will write to that file.
Joined: Sep 14, 2012
PrintStream object is already constructed, filled with data and passed to me.
I need a way to save already constructed and filled stream object to a file. (Maybe this is not how streams work?)
I cannot write my initial stream to a file, because it wasn't decorated with file output capability, because at the time of construction
I didn't know whether it will be saved to a file.
Perhaps this cannot be done, and I shoud return my data as a POJO, and then open a stream for writing to a file?
Question is, how can I write generic OutputStream (which wasnt created with file writing capability in mind) to a file.