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.





















Home »
  Java Tutorial »
    java.lang »




Boolean
Byte
Character
Class
Double
Enum
Float
Integer
Long
Math
Number
Object
Package
Process
ProcessBuilder
Runnable
Runtime
SecurityManager
Short
StackTraceElement
StrictMath
String
StringBuffer
StringBuilder
System
Thread
ThreadGroup
ThreadLocal
Throwable