IO(字节流写入与输出Demo)

2017-12-31  本文已影响0人  menmo_O
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"),"UTF-8");

        char[] buf = new char[10];
        int len = isr.read(buf);

        String str = new String(buf,0,len);
        System.out.println(str);
        isr.close();
    }
    public static void writeText() throws IOException
    {
        OutputStreamWriter osw = new OutputStreamWriter(new FileOutputStream("gbk.txt"),"UTF-8");
        osw.write("小萝莉漫许可证");
        osw.close();
    }
}
上一篇下一篇

猜你喜欢

热点阅读