import java . io .* ;
public class StandardIO
{
public static void main (String [ ] args) throws IOException
{
PrintStream console = System . out ;
// InputStream stdin = System .in ; // 为什么不需要恢复该对象
BufferedInputStream in = new BufferedInputStream (
new FileInputStream ("StandardIO.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) ;
}
}
你也可以試試不恢復 System.out 看會咋個樣。
理論上,程式都結束了,恢復不恢復都沒關係了。