当前位置:编程学习 > JAVA >>

I/O类包括节点流类和包装流类

Reader和Writer是所有字符流类的抽象基类,用于简化对字符串的输入输出编程,即用于读写文本数据

实例:

[java]
import java.io.*; 
  www.zzzyk.com
public class FileReaderWriterTest { 
    public static void main(String [] args) { 
        try { 
            FileWriter writer = new FileWriter("hello.txt"); 
             
            writer.write("love_snooker"); 
             
            writer.close(); 
             
            FileReader reader = new FileReader("hello.txt"); 
             
            char[] buf = new char[12]; 
             
            int len = reader.read(buf); 
             
            System.out.println(new String(buf, 0, len)); 
        } catch (Exception e) { 
            e.printStackTrace(); 
        } 
    } 

其它函数用法请参照jdk帮助文档

补充:软件开发 , Java ,
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,