Results 1 to 8 of 8
  1. #1
    paul is offline Member
    Join Date
    Jul 2007
    Posts
    26
    Rep Power
    0

    Default I want to do is clear the console

    Hi, All I want to do is clear the console buffer (example "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 involves 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.

  2. #2
    henry_78 is offline Member
    Join Date
    Aug 2007
    Posts
    47
    Rep Power
    0

    Default

    Hi,
    U can try to lunch a dos command from a java program.
    try this:

    Runtime rt = Runtime.getRuntime();
    Process p = rt.exec("cmd /c cls");

    Bye

  3. #3
    cruxblack is offline Senior Member
    Join Date
    Jul 2007
    Posts
    130
    Rep Power
    0

    Default

    It doesn't work henry, just tried it
    Any other way besides that?

  4. #4
    brianhks is offline Senior Member
    Join Date
    Jul 2007
    Posts
    135
    Rep Power
    0

    Default

    Your out of luck on this one. Clearing the console or moving the cursor around the console is OS specific stuff. And OS specific is not what Java does. In all reality Java makes for a very poor command line application. It is limited to standard in and standard out (and standard err).

  5. #5
    henry_78 is offline Member
    Join Date
    Aug 2007
    Posts
    47
    Rep Power
    0

    Default

    Hi,
    I really didn't undrestand good what u want to do, but i can tell u one thing.
    If u want to clear the stdout buffer (the stdout is an output stream) u can do this: System.out.flush();
    This command will will force all what u have in the stdout buffer to your console, at this point the buffer will be clear, then try the command that i gave u the other time to clear the screen...i hope it works please let me know, Bye.

  6. #6
    cruxblack is offline Senior Member
    Join Date
    Jul 2007
    Posts
    130
    Rep Power
    0

    Default

    I think paul there is trying to make the Java program he made do a clearscreen when a method is call, u know, like in a shell environment where u write cls, put and enter, and then the console would go clean

    And Mr. henry there, i tried the code, it wont clear the screen

  7. #7
    henry_78 is offline Member
    Join Date
    Aug 2007
    Posts
    47
    Rep Power
    0

    Default

    I think i know now why it dosent work.
    Because i dont have a reference to the java applicationn console.
    I can have a refernce to a console i open...
    There is a method in the class System ...System.console();
    It returns a reference to the virtual machine console (if there is any).
    I dont know if it might help u.

  8. #8
    brianhks is offline Senior Member
    Join Date
    Jul 2007
    Posts
    135
    Rep Power
    0

    Default

    Wow I haven't noticed that. I spend most of my time developing for 1.5. The Console class is definitely a step in the right direction for console based apps but, it looks like it still can't clear the screen.

Similar Threads

  1. clear cache
    By Jadellll in forum New To Java
    Replies: 0
    Last Post: 03-20-2008, 10:27 AM
  2. Please clear my doubt...............
    By vinaytvijayan in forum Advanced Java
    Replies: 0
    Last Post: 12-26-2007, 07:23 PM
  3. how to clear the data of an object
    By katie in forum AWT / Swing
    Replies: 1
    Last Post: 08-06-2007, 11:50 PM
  4. Help, someone clear up Interfaces for me
    By mathias in forum New To Java
    Replies: 1
    Last Post: 08-06-2007, 03:26 AM
  5. Clear screen in java
    By lenny in forum New To Java
    Replies: 1
    Last Post: 07-30-2007, 10:43 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •