How clear console using java

  • Follow


Hi,I am using Jdk1.5 for development. I need to clear java console afterprinting 100 lines of test on console. I tried below code it isworking for compiling java (.java) but it through exception(IOException).        try {            Process dir = Runtime.getRuntime().exec("cls");            BufferedReader bufr_in = new BufferedReader(newInputStreamReader(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 systemcannot 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 morePlease guide me, where I am going wrong thing? And how I can clearconsole through my code?Regards,-aimslife
0
Reply momer114 (25) 9/7/2007 5:03:59 AM

On Sep 7, 10:03 am, AimsLife <momer...@gmail.com> wrote:> 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,> -aimslifehttp://www.rgagnon.com/javadetails/java-0469.html
0
Reply manishsw 9/7/2007 8:04:40 AM


On Fri, 07 Sep 2007 05:03:59 -0000, AimsLife <momer114@gmail.com>
wrote, quoted or indirectly quoted someone who said :

> need to clear java console after
>printing 100 lines of test on console.

see http://mindprod.com/jgloss/console.html

You just emit a string of linefeeds.
-- 
Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com
0
Reply Roedy 9/7/2007 1:55:17 PM

On Fri, 07 Sep 2007 05:03:59 -0000, AimsLife <momer114@gmail.com>
wrote, quoted or indirectly quoted someone who said :

>
>java.io.IOException: Cannot run program "cls": CreateProcess error=2,

cls is not a program. It is a an internal command to the command
processor.

You must spawn a command processor with cls as a parameter. However,
than is not a platform independent way to solve you problem.

see http://mindprod.com/jgloss/exec.html
-- 
Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com
0
Reply Roedy 9/7/2007 1:56:48 PM

Thanks, all!Regards,-aimslife..
0
Reply AimsLife 9/10/2007 5:59:11 AM

4 Replies
778 Views

(page loaded in 0.061 seconds)

Similiar Articles:













7/24/2012 11:31:55 AM


Reply: