美文网首页
IO(字节流写入与输出Demo)

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

作者: menmo_O | 来源:发表于2017-12-31 22:35 被阅读0次
    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();
        }
    }
    

    相关文章

      网友评论

          本文标题:IO(字节流写入与输出Demo)

          本文链接:https://www.haomeiwen.com/subject/ozfzgxtx.html