I need that my program would support the operation :
java -jar filename.jar < input3.txt
I don't realy know how to deal with such command. How can I read the input file in my main program? I need to read the txt file line by line.
I need that my program would support the operation :
java -jar filename.jar < input3.txt
I don't realy know how to deal with such command. How can I read the input file in my main program? I need to read the txt file line by line.
You have the answer for your question in this post.
The main method of your program has to be ready to accept the file path in its arguments (and do what it has to do with the file).
If the file path is the first argument, then you can access it through the first position of the arguments array.
public class MainClass {
public static void main(String[] args) {
String filePath = args[0];
}
}
To execute, you'll just have to do:
java -jar filename.jar input3.txt
I found a solution, i used the command
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
for the input