-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathRedirecting.java
More file actions
47 lines (35 loc) · 959 Bytes
/
Redirecting.java
File metadata and controls
47 lines (35 loc) · 959 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package io;
import java.io.*;
import java.util.*;
/**
* RUN:
* javac io/Redirecting.java && java io.Redirecting
*
* OUTPUT:
*
*/
public class Redirecting {
public static void main(String[] args) throws IOException {
PrintStream console = System.out;
BufferedInputStream in = new BufferedInputStream(
new FileInputStream("io/Redirecting.java")
);
PrintStream out = new PrintStream(
new BufferedOutputStream(
new FileOutputStream("io/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);
}
}