Make the console wait for a user input to close

后端 未结 8 985
遥遥无期
遥遥无期 2020-11-30 01:49

I have a console application that after performing its tasks, must give feedback to the user, such as \"operation completed\" or \"operation failed\" and the detailed error.

8条回答
  •  粉色の甜心
    2020-11-30 02:05

    I've put in what x4u said. Eclipse wanted a try catch block around it so I let it generate it for me.

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

    It can probably have all sorts of bells and whistles on it but I think for beginners that want a command line window not quitting this should be fine.

    Also I don't know how common this is (this is my first time making jar files), but it wouldn't run by itself, only via a bat file.

    java.exe -jar mylibrary.jar
    

    The above is what the bat file had in the same folder. Seems to be an install issue.

    Eclipse tutorial came from: http://eclipsetutorial.sourceforge.net/index.html

    Some of the answer also came from: Oracle Thread

提交回复
热议问题