By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,949 Members | 889 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,949 IT Pros & Developers. It's quick & easy.

Can't set back System.out

P: n/a
Hi Folks,

I have tried to redirect system.out for a while and then set it back,
but it can't set it back as following program snapshot

ByteArrayOutputStream baos = new ByteArrayOutputStream();
System.setOut(new PrintStream(baos, true));
System.out.println("hello");
System.err.println(baos);
System.setOut(System.out);
System.out.println("after hello\n");
Only display "hello" in system.err and nothing in system .out
Regards,
FilexBB
Jul 17 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
FilexBB wrote:
Hi Folks,

I have tried to redirect system.out for a while and then set it back,
but it can't set it back as following program snapshot

ByteArrayOutputStream baos = new ByteArrayOutputStream();
System.setOut(new PrintStream(baos, true));
System.out.println("hello");
System.err.println(baos);
System.setOut(System.out);
System.out.println("after hello\n");
Only display "hello" in system.err and nothing in system .out
Regards,
FilexBB

I had a similar problem:

int so = 0;

int x = 5;
so = x;
so = so;
and after that code... "so" is still 5. :-(
Jul 17 '05 #2

P: n/a
"Miguel De Anda" <sodamnmad@_hotmail_.com> wrote in message
news:40******************************@news.teranew s.com...
FilexBB wrote:
Hi Folks,

I have tried to redirect system.out for a while and then set it back,
but it can't set it back as following program snapshot

ByteArrayOutputStream baos = new ByteArrayOutputStream();
System.setOut(new PrintStream(baos, true));
System.out.println("hello");
System.err.println(baos);
System.setOut(System.out);
System.out.println("after hello\n");
Only display "hello" in system.err and nothing in system .out
Regards,
FilexBB

I had a similar problem:

int so = 0;

int x = 5;
so = x;
so = so;
and after that code... "so" is still 5. :-(

Is this even for real? What in the world would you expect?
Jul 17 '05 #3

P: n/a
On Fri, 19 Mar 2004 06:39:35 -0600, "Ryan Stewart"
<zz********@gSPAMo.com> wrote:
"Miguel De Anda" <sodamnmad@_hotmail_.com> wrote in message
news:40******************************@news.terane ws.com...
FilexBB wrote:
> Hi Folks,
>
> I have tried to redirect system.out for a while and then set it back,
> but it can't set it back as following program snapshot
>
> ByteArrayOutputStream baos = new ByteArrayOutputStream();
> System.setOut(new PrintStream(baos, true));
> System.out.println("hello");
> System.err.println(baos);
> System.setOut(System.out);
> System.out.println("after hello\n");
>
>
> Only display "hello" in system.err and nothing in system .out
>
>
> Regards,
> FilexBB

I had a similar problem:

int so = 0;

int x = 5;
so = x;
so = so;
and after that code... "so" is still 5. :-(


Is this even for real? What in the world would you expect?


Me suspects that he/she was demonstrating why the OP's code wasn't
working in a simpler way.

output = console
output = byteoutputstream
output = output

--
now with more cowbell
Jul 17 '05 #4

P: n/a
fi*****@yahoo.com.hk (FilexBB) wrote in message news:<70**************************@posting.google. com>...
Hi Folks,

I have tried to redirect system.out for a while and then set it back,
but it can't set it back as following program snapshot

ByteArrayOutputStream baos = new ByteArrayOutputStream();
System.setOut(new PrintStream(baos, true));
System.out.println("hello");
System.err.println(baos);
System.setOut(System.out);
System.out.println("after hello\n");
Only display "hello" in system.err and nothing in system .out
Regards,
FilexBB System.setOut(System.out);

This System.out is still reassigned to baos-printstream.
Do the following:

PrintStream ps = System.out; //backup
......
System.setOut(ps); //restore
Jul 17 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.