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

Popular posts from this blog

javascript - backbone.js Collection.add() doesn't `construct` (`initialize`) an object -

php - Get uncommon values from two or more arrays -

Adding duplicate array rows in Php -