Adding print streams together
Hello, im working on a program, however i have a need to have 2 print streams and i wish to add the contents of one to another
The problem is i cant declare writer 2 without giving it a file url the same as newwriter, so basically i end up with 2 files when i only really want one, but it is required of me to maintain both streams. I have also tried using the writer class and appending that to writer but it just outputs java.io.FileWriter@6e1408. Any help would be great
private static PrintStream newwriter;
private static PrintStream writer2;
newwriter = new PrintStream("test.txt");
writer2 = new PrintStream(); // dont want a new file output, just need the stream
//what i want to do
Re: Adding print streams together
Why do you want two separate streams going to the same file?
You could try using a ByteOutputStream as the target for both PrintStreams and then write the ByteOutputStream to a file.