I tried to use the below command line to execute jar file, but whatever follow the "<" had been omit. I have tried to find the solution on the internet, but no luck. Can you please help me?
我尝试使用下面的命令行来执行jar文件,但是“<”之后的任何内容都被省略了。我试图在互联网上找到解决方案,但没有运气。你能帮我么?
How can I execute jar file in UNIX-like using this command line:
如何使用此命令行在UNIX中执行jar文件:
java -jar mysolution.jar < inputfile.txt
Thanks
1 个解决方案
#1
1
Assuming mysolution.jar
contains a main method like this:
假设mysolution.jar包含这样的main方法:
public static void main(String[] args) {
...
}
Anything after mysolution.jar
in your command will be filled into the args
String array. So if you run this:
在命令中的mysolution.jar之后的任何内容都将填充到args String数组中。所以,如果你运行这个:
java -jar mysolution.jar inputfile.txt
Then in your main method args
will be an array of length 1, whose only value is the String inputfile.txt
.
然后在你的main方法中,args将是一个长度为1的数组,其唯一值是String inputfile.txt。
You will then have to write the code that opens that file and does something with it.
然后,您必须编写打开该文件的代码并对其执行某些操作。
Your original approach would replace stdin
with a file stream coming from that file. To work with the file that way you would have to use a Scanner
您的原始方法将使用来自该文件的文件流替换stdin。要以这种方式使用文件,您必须使用扫描仪
Here's another question/answer with some details on reading a file via stdin
这是关于通过stdin读取文件的一些细节的另一个问题/答案
#1
1
Assuming mysolution.jar
contains a main method like this:
假设mysolution.jar包含这样的main方法:
public static void main(String[] args) {
...
}
Anything after mysolution.jar
in your command will be filled into the args
String array. So if you run this:
在命令中的mysolution.jar之后的任何内容都将填充到args String数组中。所以,如果你运行这个:
java -jar mysolution.jar inputfile.txt
Then in your main method args
will be an array of length 1, whose only value is the String inputfile.txt
.
然后在你的main方法中,args将是一个长度为1的数组,其唯一值是String inputfile.txt。
You will then have to write the code that opens that file and does something with it.
然后,您必须编写打开该文件的代码并对其执行某些操作。
Your original approach would replace stdin
with a file stream coming from that file. To work with the file that way you would have to use a Scanner
您的原始方法将使用来自该文件的文件流替换stdin。要以这种方式使用文件,您必须使用扫描仪
Here's another question/answer with some details on reading a file via stdin
这是关于通过stdin读取文件的一些细节的另一个问题/答案