复制代码
- //:Redirecting.java
- //Demonstratestheuseofredirectionfor
- //standardIOinJava1.1
- importjava.io.*;
- classRedirecting{
- publicstaticvoidmain(String[]args){
- try{
- BufferedInputStreamin=
- newBufferedInputStream(
- newFileInputStream(
- "Redirecting.java"));
- //Producesdeprecationmessage:
- PrintStreamout=
- newPrintStream(
- newBufferedOutputStream(
- newFileOutputStream("test.out")));
- System.setIn(in);
- System.setOut(out);
- System.setErr(out);
- BufferedReaderbr=
- newBufferedReader(
- newInputStreamReader(System.in));
- Strings;
- while((s=br.readLine())!=null)
- System.out.println(s);
- out.close();//Rememberthis!
- }catch(IOExceptione){
- e.printStackTrace();
- }
- }
- }///:~
欢迎光临 仓酷云 (http://ckuyun.com/) | Powered by Discuz! X3.2 |