System: setIn(InputStream in) : System « java.lang « Java by API






System: setIn(InputStream in)

  
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintStream;

public class Main {
  public static void main(String[] args) throws IOException {
    PrintStream console = System.out;
    BufferedInputStream in = new BufferedInputStream(new FileInputStream("Redirecting.java"));
    PrintStream out = new PrintStream(new BufferedOutputStream(new FileOutputStream("test.out")));
    System.setIn(in);
    System.setOut(out);
    System.setErr(out);
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    String s;
    while ((s = br.readLine()) != null)
      System.out.println(s);
    out.close(); 
    System.setOut(console);
  }
}

   
    
  








Related examples in the same category

1.System.exit(int status)
2.System.in
3.System.in.read()
4.System.out
5.System: arraycopy(Object src, int srcPos, Object dest, int destPos, int length)
6.System: clearProperty(String key)
7.System: console()
8.System: currentTimeMillis()
9.System: getenv(String key)
10.System: getProperty(String name)
11.System.getProperty ("user.dir")
12.System: getProperty(String key, String def)
13.System: getProperties()
14.System.identityHashCode(Object x)
15.System: nanoTime()
16.System.setErr(PrintStream err)
17.System: setOut(PrintStream err)
18.System: setProperty(String key, String value)