forked from TimSongCoder/LearnJavaForAndroid
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRedirectIODemo.java
More file actions
26 lines (23 loc) · 745 Bytes
/
Copy pathRedirectIODemo.java
File metadata and controls
26 lines (23 loc) · 745 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
import java.io.FileInputStream;
import java.io.PrintStream;
import java.util.Date;
import java.io.IOException;
public class RedirectIODemo{
public static void main(String[] args) throws IOException{
if(args.length!=3){
System.err.println("usage: java RedirectIODemo inputSource outDest errDest.");
return;
}
System.setIn(new FileInputStream(args[0]));
System.setOut(new PrintStream(args[1]));
System.setErr(new PrintStream(args[2]));
int ch;
while((ch=System.in.read())!=-1){
//System.out.print((char)ch); // with charset problem
System.out.write(ch);
}
System.err.println("This is error log.");
System.err.println();
System.err.println("Permission Denied." + new Date(System.currentTimeMillis()));
}
}