java - How to direct std input from file in Eclipse -
how can take input file in eclipse?
direct i/o file command line.
java myprogram < input.txt >output.txt
unable direct input.
output directing easy. go->run->run->configurations->common
if need use default in
can this:
system.setin(new fileinputstream("testfile.txt"));
a sample of how works follows:
import java.io.bufferedreader; import java.io.fileinputstream; import java.io.fileoutputstream; import java.io.ioexception; import java.io.inputstreamreader; public class testsystemin { public static void main(final string[] args) throws ioexception { // prepare test fileoutputstream fos = new fileoutputstream("testfile.txt"); fos.write("testtoken".getbytes()); // configure env system.setin(new fileinputstream("testfile.txt")); // perform read test bufferedreader br = new bufferedreader(new inputstreamreader(system.in)); system.out.println("read: " + br.readline()); } }
the output done in same way using:
system.setout(new printstream("testfile.txt"));
Comments
Post a Comment