| View previous topic :: View next topic |
| Author |
Message |
Québec Guest
|
Posted: Sat Nov 22, 2003 10:28 pm Post subject: System.setOut |
|
|
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
|
Posted: Sat Nov 22, 2003 10:50 pm Post subject: Re: System.setOut |
|
|
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
|
Posted: Mon Nov 24, 2003 1:05 pm Post subject: Re: System.setOut |
|
|
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
|
Posted: Mon Nov 24, 2003 1:39 pm Post subject: Re: System.setOut |
|
|
"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
|
Posted: Mon Nov 24, 2003 4:51 pm Post subject: Re: System.setOut |
|
|
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
|
Posted: Mon Nov 24, 2003 5:07 pm Post subject: Re: System.setOut |
|
|
"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
|
Posted: Mon Nov 24, 2003 6:07 pm Post subject: Re: System.setOut |
|
|
| 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 |
|
 |
|