[英]execute a jar file by assigning it to a button injava fxml
I have a sample FXML code with single button. 我有一个带有单个按钮的示例FXML代码。
protected void doSomething() {
System.out.println("The button was clicked!");
}
}
dosomething()
is the button Id. dosomething()
是按钮ID。 If I click on that button, it displays that the button was clicked. 如果单击该按钮,则显示该按钮已被单击。 What is the proper syntax if I want to execute a jar file instead of displaying the text? 如果我想执行一个jar文件而不显示文本,正确的语法是什么?
Lets suppose your jar is named myJar.jar
then 假设您的jar名为myJar.jar
然后
Process process = Runtime.getRuntime().exec(new String[]{"java","-jar","myJar.jar"});
process.waitFor();
java.io.InputStream inputStream = process.getInputStream();
byte[] myByte = new byte[inputStream.available()];
inputStream.read(myByte, 0, myByte.length);
System.out.println(new String(myByte));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.