java转换流InputStreamReaderOutputStreamWriter

java转换流InputStreamReaderOutputStreamWriter,第1张

java转换流InputStreamReaderOutputStreamWriter
package com.seven.inputStreamReader;

import java.io.*;


public class TestInputStreamReader {
    public static void main(String[] args)throws Exception {
        InputStreamReader inputStreamReader = new InputStreamReader(new FileInputStream("D:\a.txt"),"gbk");
        char[] chars = new char[1024];
        while (true){
            int read = inputStreamReader.read(chars);
            if (read==-1)break;
            System.out.println(new String(chars,0,read));
        }
        inputStreamReader.close();

        OutputStreamWriter outputStreamWriter = new OutputStreamWriter(new FileOutputStream("d:\q.txt"),"gbk");
        for (int i = 0; i < 9; i++) {
            outputStreamWriter.write("aaaaaa中国人n");
            outputStreamWriter.flush();
        }

        outputStreamWriter.close();
    }
}

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5687353.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-17
下一篇 2022-12-17

发表评论

登录后才能评论

评论列表(0条)

保存