将字节流转成字符流

package system.system;

import java.io.*;

public class in {
    public static void main(String[] args) throws IOException {
        String filepath="d:\\hello5.txt";
//        InputStreamReader isr=new InputStreamReader(new FileInputStream(filepath));
//        BufferedReader br=new BufferedReader(isr);
        BufferedReader br=new BufferedReader(new InputStreamReader
                (new FileInputStream(filepath),"gbk"));
        String readline;
        while ((readline= br.readLine())!=null){
            System.out.println(readline);
        }
        br.close();

    }

}

转成字节流读入程序

package system.system;

import org.omg.CORBA.portable.OutputStream;

import java.io.*;

public class write {
    public static void main(String[] args) throws IOException {
        String filepath="d:\\hello5.txt";
        String charset="gbk";
        OutputStreamWriter oos=new OutputStreamWriter
                (new FileOutputStream(filepath),charset);
        oos.write("hi,韩顺平教育");
        oos.close();

    }
}

转换成字节流输出到文件

你可能感兴趣的:(java,开发语言)