Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Printstream to file

 
Rade Koncar
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

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?
 
Paul Clapham
Sheriff
Pie
Posts: 20776
30
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Of course. Just use the PrintStream constructor which takes a File object and then the PrintStream will write to that file.
 
Rade Koncar
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic