IO流-字符编码表转换示例

来源:互联网 发布:制作windows to go盘 编辑:程序博客网 时间:2024/06/02 14:36
//IO流-字符编码表转换示例import java.io.*;class EncodeStream {    public static void main(String[] args) throws IOException    {        //writeText();        readText();    }    public static void readText() throws IOException    {        InputStreamReader isr = new InputStreamReader(new FileInputStream("gbk.txt"),"gbk");        char[] buf = new char[10];//作为缓冲区        int len = isr.read(buf);        /*         int read(char[] cbuf, int offset, int length)           将字符读入数组中的某一部分。           */        String str = new String (buf, 0 ,len);        System.out.println(str);        isr.close();    }    public static void writeText() throws IOException    {        OutputStreamWriter osw = new OutputStreamWriter(new FileOuptStream("UTF.txt"),"utf-8");        osw.write("你好");        osw.close();    }}
0 0