栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

Java技能树-IO-Reader/Writer

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Java技能树-IO-Reader/Writer

1 需求


2 接口

Class Reader

java.lang.Object 

        java.io.Reader 

  • Field Detail
    • protected Object lock
  • Constructor Detail
    • protected Reader()
    • protected Reader(Object lock)
  • Method Detail
    • public abstract void close() throws IOException
    • public int read() throws IOException
    • public int read(char[] cbuf) throws IOException
    • public abstract int read(char[] cbuf, int off, int len) throws IOException
    • public int read(CharBuffer target) throws IOException

Class Writer
java.lang.Object 
        java.io.Writer 

  • Field Detail
    • protected Object lock
  • Constructor Detail
    • protected Writer()
    • protected Writer(Object lock)
  • Method Detail
    • public Writer append(char c) throws IOException
    • public Writer append(CharSequence csq) throws IOException
    • public Writer append(CharSequence csq, int start, int end) throws IOException
    • public abstract void close() throws IOException
    • public abstract void flush() throws IOException
    • public void write(char[] cbuf) throws IOException
    • public abstract void write(char[] cbuf, int off, int len) throws IOException
    • public void write(int c) throws IOException
    • public void write(String str) throws IOException
    • public void write(String str, int off, int len) throws IOException

3 示例代码

import java.io.*;

public class Test {
    public static void main(String[] args) throws IOException {
        // 字符流 示例
        Reader reader = new FileReader("C:\test.txt");
        int i = 0;
        while ((i = reader.read()) != -1) {
            System.out.println(i);
        }
        reader.close();

        System.out.println("******* 分割线 ******");

        //字节流 示例
        InputStream inputStream = new FileInputStream("C:\test.txt");
        int j = 0;
        while ((j = inputStream.read()) != -1) {
            System.out.println(j);
        }
        inputStream.close();
    }
}

import java.io.*;

public class Test {
    public static void main(String[] args) throws IOException {
        Writer writer = new FileWriter("C:\test.txt");
        writer.write("中国");
        writer.close();
    }
}

4 参考资料

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/894729.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号