How to redirect stdin and stdout to take data as input from a text file and pass data as output to another textfile.
My input and output files look like this.
Input File.txt
1 2 3
The output should be the sum of the numbers in the input file.
Output File.txt
6
You don't have to do that in Java, you can do it from the shell that runs your Java application:
The Java code can then just read from System.in and write to System.out.
This is a reflection based solution incorporating part of code from @sidgate's answer:
You can set the
System.out
andSystem.in
to a file path. Then your existing code should work