How clear console using java

A

AimsLife

Hi,

I am using Jdk1.5 for development. I need to clear java console after
printing 100 lines of test on console. I tried below code it is
working for compiling java (.java) but it through exception
(IOException).

try {
Process dir = Runtime.getRuntime().exec("cls");
BufferedReader bufr_in = new BufferedReader(new
InputStreamReader(dir.getInputStream()));
String readLine = "";
if( ( readLine = bufr_in.readLine() ) != null )
{
System.out.println(readLine);
while( ( readLine = bufr_in.readLine() ) != null )
System.out.println (readLine);
}

} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

Above code throws exception at run time.

java.io.IOException: Cannot run program "cls": CreateProcess error=2,
The system cannot find the file specified
at java.lang.ProcessBuilder.start(Unknown Source)
at java.lang.Runtime.exec(Unknown Source)
at java.lang.Runtime.exec(Unknown Source)
at java.lang.Runtime.exec(Unknown Source)
at atm.Driver.main(Driver.java :52)
Caused by: java.io.IOException: CreateProcess error=2, The system
cannot find the file specified
at java.lang.ProcessImpl.create(Native Method)
at java.lang.ProcessImpl.<init>(Unknown Source)
at java.lang.ProcessImpl.start(Unknown Source)
... 5 more

Please guide me, where I am going wrong thing? And how I can clear
console through my code?

Regards,
-aimslife
 
M

manishsw

Hi,

I am using Jdk1.5 for development. I need to clear java console after
printing 100 lines of test on console. I tried below code it is
working for compiling java (.java) but it through exception
(IOException).

try {
Process dir = Runtime.getRuntime().exec("cls");
BufferedReader bufr_in = new BufferedReader(new
InputStreamReader(dir.getInputStream()));
String readLine = "";
if( ( readLine = bufr_in.readLine() ) != null )
{
System.out.println(readLine);
while( ( readLine = bufr_in.readLine() ) != null )
System.out.println (readLine);
}

} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

Above code throws exception at run time.

java.io.IOException: Cannot run program "cls": CreateProcess error=2,
The system cannot find the file specified
at java.lang.ProcessBuilder.start(Unknown Source)
at java.lang.Runtime.exec(Unknown Source)
at java.lang.Runtime.exec(Unknown Source)
at java.lang.Runtime.exec(Unknown Source)
at atm.Driver.main(Driver.java :52)
Caused by: java.io.IOException: CreateProcess error=2, The system
cannot find the file specified
at java.lang.ProcessImpl.create(Native Method)
at java.lang.ProcessImpl.<init>(Unknown Source)
at java.lang.ProcessImpl.start(Unknown Source)
... 5 more

Please guide me, where I am going wrong thing? And how I can clear
console through my code?

Regards,
-aimslife

http://www.rgagnon.com/javadetails/java-0469.html
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,077
Latest member
SangMoor21

Latest Threads

Top