[英]Java IO with a Jar file using command line
I want to be able to open a jar file and have it open a console that I can interact with it from. 我希望能够打开一个jar文件,并使它打开一个可以与之交互的控制台。 I have tried opening the jar with
java.exe
instead of javaw.exe
, but the window that appears closes almost instantly when I try to run the program. 我尝试用
java.exe
而不是javaw.exe
打开jar,但是当我尝试运行程序时,出现的窗口几乎立即关闭。 What am I doing wrong? 我究竟做错了什么?
Your program is closed because it is not waiting for input data. 您的程序已关闭,因为它不等待输入数据。
See example: 参见示例:
public static void main(String[] args) throws Exception {
System.out.println("Hello! I'm waiting for input...");
args = new Scanner(System.in).nextLine().split(" ");
System.out.println("I received your data: \r\n\r");
for(int i=0; i<args.length; i++) System.out.print(args[i] + " ");
System.out.println("\r\n\rAfter 10 second I'll close");
Thread.sleep(10 * 1000);
// Here program did not waiting for input and was closed automatically;
}
What shown in console: 控制台中显示的内容:
C:\Users\user>java -jar "C:\myprogram.jar"
Hello! I'm waiting for input...
bla blabla bla bla // I did enter it to console
I received your data:
bla blabla bla bla
After 10 second I'll close
After 10 seconds program was closed, because not waiting for input data. 10秒后,由于不等待输入数据,程序已关闭。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.