English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

How can i clear the output console window? e.g. I print some lines using System.out.print and lets say it has 6 lines there. Then how do i clear or erase all of that O.R.
is there any way that the cursor can be moved back to the top of the text so the next time i print something it prints it on the top.
Thanks.

2007-03-28 10:53:24 · 2 answers · asked by Anonymous in Computers & Internet Programming & Design

2 answers

New Question for the "Asker"...

Could you give us more details of what you are attempting to do, or how this need of yours fits in to the app you are developing? (The reason I ask, is that there may be a better way to go about doing what you are attempting to do using the Screen Buffer. Feel free to e-mail me if you don't wish to post all that publicly.) Also, see my Edit # 1 below including a code snippet for you.

=============================

Edit # 1:

Ok, so far I could not find anything else that I personally deemed an "acceptable" solution to what you are trying to do. Here is the code that will accomplish what the codeguru folks said was a possible solution:

for( int i=0; i<350; i++ )
System.out.println();

Note though, that depending on how your Cmd Prompt window Properties are set, the above may not do the trick. Any person can set their Properties to have a screen buffer height that is greater than 350 lines (the default on my XP machine was 300, if I recall correctly). So you can not necessarily trust that the above code would clear *everyone's* screen of the output console window. But if your own output console window is all you are concerned about, you are ok. So you will want to do one of two things, if you use the above code:

If you are only concerned about running your app on your own computer... set your screen buffer height to under 350. Do this by right-clicking your Cmd Prompt shortcut icon, clicking the "Layout" tab, and modifying the "Height" setting under "Screen Buffer Size" to say, 300, like mine. Click "Apply", then "Ok", and you're done. (You can also set this for an individual window by left-clicking the upper left which I believe is called the control menu? Then click Properties, and follow the same steps as above.)

If you are concerned about running your app on other people's machines, which is almost always the case when I am programming... the only way you could attempt to make up for the fact that some folks will have their Screen Buffer Height set to higher, is to up the number of reps, maybe:

for( int i=0; i<700; i++ )
System.out.println();

There still might be some folks out there whose Screen Buffer Height is set higher than this, but I am hoping they will be few and far between... can't be sure about that... but it's the best answer I can think of so far.

The more reps, the slower the app becomes, of course, but the 350 is not painfully slow. I didn't try the 700. See which you prefer.

=============================

Original Answer:

The answer given at codeguru.com seems to have been, that there is no real good way to do this sort of thing using Java. However, they did give some suggestions, like this one:

"There is no command in Java to do this. You could print a number of blank lines which effectively scrolls anything that is visible off the top of the screen. But we warned that you dont have exclusive access to the console, for example exception stack traces can get printed to the console (unless you redirect the err output stream)."

I will keep searching, and if I find anything else out, I will edit this answer, so keep re-reading it to see if I managed to find out any other answers.

2007-03-28 11:13:18 · answer #1 · answered by prodaugh-internet 3 · 0 0

? what does this question have to do with JAVA.... Lol...

2007-03-28 10:57:08 · answer #2 · answered by the s0urce 3 · 0 3

fedest.com, questions and answers