改变in out 格式

package yuwei.com;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.PrintStream;
//改变in out 格式
public class OutputStreamWriterDemo {

    public static void main(String[] args) {
        BufferedReader br = null;
        BufferedWriter bufw = null;
        String line = null;
        try {
            System.setIn(new FileInputStream("D:\\java学习\\IoStudy\\src\\yuwei\\com\\WriteAppendDemo.java"));
            System.setOut(new PrintStream("zzz.txt"));

             br = new BufferedReader(new InputStreamReader(System.in));
            bufw = new BufferedWriter(new OutputStreamWriter(System.out));

            while((line = br.readLine())!=null) {
                if("over".equals(line)) {
                    break;
                }else {
                    //会在控制台输出
                    bufw.write(line);
                    bufw.newLine();
                    bufw.flush();
                }
            }
        }catch(IOException e) {
            System.out.println(e.toString());
        }finally {
            try {
                br.close();
                bufw.close();

            }catch(IOException e) {
                System.out.println(e.toString());
            }
        }   

    }

}
阅读更多
版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/weixin_40051278/article/details/80693624
个人分类: IO Java System
上一篇从文件到控制台的输出
下一篇File类初次使用
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

关闭
关闭
关闭