Keep the console open after execution (this howto is deprecated)Tag(s): DEPRECATED


Call the static method PressAnykey to keep to "DOS" window open.
import java.io.*;
public class IO {
  public static void PressAnyKey() {
    BufferedReader input = 
      new BufferedReader(new InputStreamReader(System.in));
    System.out.print("Press any key...");
    try { input.readLine();}
    catch (Exception e) { e.printStackTrace();}
    }
}
For example
public class HelloWorld {
 public static void main(String[] args) {
   System.out.println("Hello world.");
   IO.PressAnyKey();       
   }
}

blog comments powered by Disqus