【发布时间】:2017-06-18 20:52:47
【问题描述】:
基本上我是个新手,现在我遇到了一个问题,即使在阅读了关于这个主题的所有其他相关帖子后我也无法解决:( 我正在尝试使用两个参数启动一个 .jar 文件(我们称之为 test.jar)。我的批处理文件位于同一目录中。 这是我没有得到的部分: 这两个参数应该是我之前拖放到 .bat 文件上的文件的文件名。 它应该像这样工作: 我将第一个文件拖放到 .bat 文件上。然后我将第二个文件放到 .bat 文件中。现在 .jar 启动并显示两个文件名。 (最好是通过这个看不到dos-Window。) (到目前为止,我只是用一个文件得到它,但是当我将另一个文件放到 .bat 上时,它只会启动另一个 .bat-Window。) 这是我的 .jar 文件的主要方法:
public static void main(String[] args) {
JFrame frame = new JFrame(); //build JFrame
frame.setSize(400,400);
JTextField t = new JTextField(); //build TextField to display the args
t.setBounds(10, 10, 300, 100);
if(args.length>=1){ //if there is at least one argument, then print out the name of the file
t.setText("First File: "+args[0]);
if(args.length>=2) //if there is more then one argument, then print out the name of the files
t.setText(t.getText()+" Second File: "+args[1]);
else //if there are not more then one argument
t.setText(t.getText()+" 2nd Not found");
}else{ //if there ist no argument
t.setText("1st not found");
}
frame.add(t); //add TextField
frame.setVisible(true); //set Visible
}
【问题讨论】:
标签: java windows batch-file cmd