Results 1 to 2 of 2
Like Tree1Likes
  • 1 Post By Norm

Thread: Adding print streams together

  1. #1
    trishtren is offline Member
    Join Date
    Feb 2011
    Rep Power

    Default 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
    Java Code:
    	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
    writer2.append("test sentence");
    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 Any help would be great

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Eastern Florida
    Rep Power

    Default 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.
    Fubarable likes this.
    If you don't understand my response, don't ignore it, ask a question.

Similar Threads

  1. Adding print streams
    By trishtren in forum New To Java
    Replies: 0
    Last Post: 04-21-2012, 08:44 PM
  2. Cmd process streams
    By helloworld922 in forum Advanced Java
    Replies: 0
    Last Post: 10-20-2010, 09:20 AM
  3. Print the text file and print preview them
    By Java Tip in forum java.awt
    Replies: 0
    Last Post: 06-23-2008, 12:04 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts