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?
How can I execute jar file in UNIX-like using this command line:
java -jar mysolution.jar < inputfile.txt
Thanks
Assuming mysolution.jar
contains a main method like this:
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:
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
.
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
Here's another question/answer with some details on reading a file via stdin
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.