Results 1 to 6 of 6

Thread: How to Clear Java Console?

  1. #1
    Join Date
    Jan 2010
    Posts
    311

    How to Clear Java Console?

    Hello,
    I started in java and I would like to delete the text displayed in the console but I can not find how. I saw that it depended on the bones, thus making it the program is more portable, are that true? I want to display a menu, and when scanning, clear the menu to display something else, you have a solution? Thank you in advance

  2. #2
    Join Date
    Dec 2009
    Posts
    211

    Re: How to Clear Java Console?

    Yes when you use the command system your program is more portable
    Linux for the console to clear => clear
    and windows => cls

    First solution
    execute two commands in a try catch, one that does not generate an exception repairable and another run

    The second solution run your command by bone
    String cmd = "";
    if linux
    cmd = "clear"
    if windows
    cmd = "cls";
    if macos
    cmd: ...

  3. #3
    Join Date
    Dec 2009
    Posts
    192

    Re: How to Clear Java Console?

    Hello,
    Here is the code you are looking for
    Code:
    try (
      if(System.getProperty ("os.name"). startsWith ("you operating system"))
        Runtime.getRuntime (). Exec ("cls");
      else
        Runtime.getRuntime (). Exec ("clear");
    ) catch(Exception e) (
      for(int x = 0; x <100: x + +)
        System.out.println ();
    )

  4. #4
    Join Date
    Mar 2010
    Posts
    197

    Re: How to Clear Java Console?

    I think it's simply impossible that you request. You talk about the console in which to run your java app? remains the best
    Code:
    for (int i = 0; i <40: i + +) 
            System.out.println ("\ n");
    What you gain in readability.

  5. #5
    Join Date
    Nov 2009
    Posts
    330

    Re: How to Clear Java Console?

    Hey,
    alternatively you can try the following

    Code:
    void clear () (Runtime runtime = Runtime.getRuntime (); String args [] = ("bin / sh", "-c", "clear") try (final Process p = Runtime.exec (args);) catch (Exception e) (System.out.println (e);))
    Remember this will only work with linux based operating system and not with windows operating system.

  6. #6
    Join Date
    Aug 2009
    Posts
    155

    Re: How to Clear Java Console?

    I copied the code, I wrote to the database:
    Code:
    String [] args = ("/ bin / sh", "-c", "Clear")
    I tried to write except e, but it does not hold myself out to the console. I do not understand why, I followed your instructions. Currently, I just tested this version:
    Code:
    final String ESC = "\ 033 [" System.out.println (ESC + "2J"); System.out.flush ();
    A portion of the screen disappears but it does not exactly like the command "clear". Thank you for your support.

Similar Threads

  1. Java Console does not start
    By KALYAN23 in forum Software Development
    Replies: 6
    Last Post: 28-07-2010, 10:26 AM
  2. Java console problem with Firefox
    By Messenger in forum Windows Software
    Replies: 5
    Last Post: 27-07-2010, 10:35 AM
  3. Timestamps on Java Console
    By Kshaunish in forum Operating Systems
    Replies: 5
    Last Post: 23-07-2010, 06:02 AM
  4. Java - Reading from console
    By WinDoWLoCuS in forum Software Development
    Replies: 3
    Last Post: 09-11-2009, 12:18 PM
  5. IE7/console slow Java
    By Zidaan in forum Technology & Internet
    Replies: 4
    Last Post: 20-11-2008, 06:50 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,713,518,900.88074 seconds with 17 queries