3 Years
Discussion Span
Last Post by JamesCherrill

Sadly, there is no command or functionality like that in the language. You could however call the system command to execute the console command, but that may not be what you want.


run time of java prgram we write simply cls in console window it clear the screen but i need a command that i give in my code it clear my screen autometically. and how to call system command to execute the console command.


By "screen" do you mean the console window, as in System.out? If so, be aware that the console output device may be to a printer or a sequential file, in which case "clear the screen" makes no sense, and attempting to execute a "cls" as a system command will have unpredicatable reuslts in such cases (and if you use the wrong command for the OS that happens to be running at the time). Also, as far as I can find out, there is no cls functionality in standard C++ either; it's just that some implementations of C++ have it as a non-standard addition.

Your safest option is just to send a load of newlines to the console device.

It's not worth spending any real effort on this - console I/O is used in the early stages of teaching Java, but you won't ever use it again except as a logging device for errors etc.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.