AppletTalk.com Forum Index AppletTalk.com
Java discussions newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

System.setOut

 
Post new topic   Reply to topic    AppletTalk.com Forum Index -> Java Help
View previous topic :: View next topic  
Author Message
Québec
Guest





PostPosted: Sat Nov 22, 2003 10:28 pm    Post subject: System.setOut Reply with quote



Hi, I was sure this one would be simple :-)

The output stream does not comes back to the console.

APrintStream ps = new APrintStream(new FileOutputStream(registered));
System.setOut(ps);
System.out.println("AB-09-RTY-099");
ps.checkError();
ps.close();
System.setOut(System.out);
System.out.println("The console is back.");
JOptionPane.showMessageDialog(null,
"well well")

Jean Pierre


Back to top
Jonas Kongslund
Guest





PostPosted: Sat Nov 22, 2003 10:50 pm    Post subject: Re: System.setOut Reply with quote



Québec wrote:
Quote:
The output stream does not comes back to the console.

APrintStream ps = new APrintStream(new
FileOutputStream(registered));

Add this line:
OutputStream savedOut = System.out;

Quote:
System.setOut(ps);
System.out.println("AB-09-RTY-099");
ps.checkError();
ps.close();

Replace this line

Quote:
System.setOut(System.out);

with this line
System.setOut(savedOut);

Quote:
System.out.println("The console is back.");
JOptionPane.showMessageDialog(null,
"well well")

--
Jonas Kongslund

Back to top
Québec
Guest





PostPosted: Mon Nov 24, 2003 1:05 pm    Post subject: Re: System.setOut Reply with quote



Your solution did not work. I replaced aprintStream with a system class
without success.

PrintStream ps = new APrintStream(new FileOutputStream(registered));
System.setOut(ps);
ps.println("AB-09-RTY-099");
ps.checkError();
ps.close();
System.setOut(System.out);

"Jonas Kongslund" <dont (AT) mail (DOT) me.at.all> wrote

Quote:
Québec wrote:
The output stream does not comes back to the console.

APrintStream ps = new APrintStream(new
FileOutputStream(registered));

Add this line:
OutputStream savedOut = System.out;

System.setOut(ps);
System.out.println("AB-09-RTY-099");
ps.checkError();
ps.close();

Replace this line

System.setOut(System.out);

with this line
System.setOut(savedOut);

System.out.println("The console is back.");
JOptionPane.showMessageDialog(null,
"well well")

--
Jonas Kongslund



Back to top
Anthony Borla
Guest





PostPosted: Mon Nov 24, 2003 1:39 pm    Post subject: Re: System.setOut Reply with quote


"Québec" <jpda (AT) vidn (DOT) ca> wrote

Quote:

Your solution did not work. I replaced aprintStream with a system class
without success.

PrintStream ps = new APrintStream(new
FileOutputStream(registered));
System.setOut(ps);
ps.println("AB-09-RTY-099");
ps.checkError();
ps.close();
System.setOut(System.out);


The example I posted works perfectly well. Here is a snippet:

PrintStream ops = System.out;
...
System.setOut(nps);
...
nps.close();
...
System.setOut(ops);

I hope this helps.

Anthony Borla



Back to top
Chris Smith
Guest





PostPosted: Mon Nov 24, 2003 4:51 pm    Post subject: Re: System.setOut Reply with quote

Québec wrote:
Quote:
Your solution did not work. I replaced aprintStream with a system class
without success.

PrintStream ps = new APrintStream(new FileOutputStream(registered));
System.setOut(ps);
ps.println("AB-09-RTY-099");
ps.checkError();
ps.close();
System.setOut(System.out);

Huh? That's the same code you started out with! Did you try Jonas'
suggestion at all?

--
www.designacourse.com
The Easiest Way to Train Anyone... Anywhere.

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation

Back to top
Tor Iver Wilhelmsen
Guest





PostPosted: Mon Nov 24, 2003 5:07 pm    Post subject: Re: System.setOut Reply with quote

"Québec" <jpda (AT) vidn (DOT) ca> writes:

Quote:
System.setOut(System.out);

You need to learn that the above statement in effect is a noop.

Back to top
Québec
Guest





PostPosted: Mon Nov 24, 2003 6:07 pm    Post subject: Re: System.setOut Reply with quote

Quote:
You need to learn that the above statement in effect is a noop.
Oops! ...what's a noop?


Quote:
Did you try Jonas' suggestion at all?
Yes. It seems one has to 'save' the current output 'before' changing it. I

dont see why but it works.


PrintStream ops = System.out; === save the output

PrintStream fps = new APrintStream(new FileOutputStream(registered));
System.setOut(fps);
fps.println("AB-09-RTY-099");
fps.checkError();
fps.close();

System.setOut(ops); === get it back



Back to top
Display posts from previous:   
Post new topic   Reply to topic    AppletTalk.com Forum Index -> Java Help All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.