Go Back   CodingForums.com > :: Server side development > Java and JSP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 09-15-2005, 04:31 PM   PM User | #1
dcoder
New to the CF scene

 
Join Date: Dec 2004
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
dcoder is an unknown quantity at this point
Clearing the console in Java

I'm going mad everyone.

All I want to do is clear the console's buffer (i.e. "cls in Windows, "clear" in Unix).

I've googled this quite a bit and found nothing useful.

Sun's forums are completely useless, there are about 20 threads asking the same question and the only replies are to put in a loop with a bunch of System.out.println(). There is another "solution" but it's a nasty hack that involes editing system files (and thus makes it difficult to distribute my application!).

I'm just not convinced that there's "no way to do it."

Does ANYONE know how to clear the console??!

Thanks,
Kyle

Edit: Also, I've tried using Runtime.exec() to execute the "cls" command, but that seems to start a new console session.

Last edited by dcoder; 09-15-2005 at 04:34 PM..
dcoder is offline   Reply With Quote
Old 09-16-2005, 04:43 PM   PM User | #2
nikkiH
Senior Coder

 
nikkiH's Avatar
 
Join Date: Jun 2005
Location: Near Chicago, IL, USA
Posts: 1,973
Thanks: 1
Thanked 32 Times in 31 Posts
nikkiH is on a distinguished road
There is a way -- by outputting 80 empty lines.

Java does not assume standard out is a console. Therefore, it has no way to clear it. Java is about cross-platform applications.
If you want to clear the console, you have to be making an assumption there IS one. Therefore, it is no longer cross-platform.
__________________

If this post contains any code, I may or may not have tested it. It's probably just example code, so no getting knickers in a bunch over a typo, OK? If it doesn't have basic error checking in it, such as object detection or checking if objects are null before using them, put that in there. I'm giving examples, not typing up your whole app for you. You run code at your own risk.
Bored? Visit
http://www.kaelisspace.com/
nikkiH is offline   Reply With Quote
Old 09-16-2005, 05:37 PM   PM User | #3
dcoder
New to the CF scene

 
Join Date: Dec 2004
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
dcoder is an unknown quantity at this point
Heh. Again, I refuse to print a bunch of empty lines. There's got to be a more elegant way to do it!

And just because Java doesn't assume standard out is a console doesn't mean there isn't a way to clear it. Java can write to the console without having to assume standard out is a console, so why should it have to assume this in order to clear it?

Maybe I'm just being to stubborn with this one ...I may have to email Sun.
dcoder is offline   Reply With Quote
Old 09-16-2005, 05:44 PM   PM User | #4
dcoder
New to the CF scene

 
Join Date: Dec 2004
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
dcoder is an unknown quantity at this point
Alright, I admit defeat. I just followed the heirarchy upwards from the PrintStream 'out' in System, and it looks like nowhere in this heirarchy is a formal method for clearing the OutputStream defined.



I guess I'll have to find another way to write text that can easily be cleared...
dcoder is offline   Reply With Quote
Old 09-16-2005, 06:53 PM   PM User | #5
nikkiH
Senior Coder

 
nikkiH's Avatar
 
Join Date: Jun 2005
Location: Near Chicago, IL, USA
Posts: 1,973
Thanks: 1
Thanked 32 Times in 31 Posts
nikkiH is on a distinguished road
Well, why are you using the console for this, then?
Use a real GUI (swing, etc) and you can clear whatever you want...
__________________

If this post contains any code, I may or may not have tested it. It's probably just example code, so no getting knickers in a bunch over a typo, OK? If it doesn't have basic error checking in it, such as object detection or checking if objects are null before using them, put that in there. I'm giving examples, not typing up your whole app for you. You run code at your own risk.
Bored? Visit
http://www.kaelisspace.com/
nikkiH is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 04:37 AM.


Advertisement
Log in to turn off these ads.