System.setIn(InputStream in) has the following syntax.
public static void setIn(InputStream in)
In the following code shows how to use System.setIn(InputStream in) method.
//www.j av a 2 s . c om import java.io.FileInputStream; public class Main { public static void main(String[] args) throws Exception { System.setIn(new FileInputStream("file.txt")); char ret = (char)System.in.read(); System.out.println(ret); } }
The code above generates the following result.