Java System.setIn(InputStream in)
Syntax
System.setIn(InputStream in) has the following syntax.
public static void setIn(InputStream in)
Example
In the following code shows how to use System.setIn(InputStream in) method.
/*www. j a v a 2 s . co m*/
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.