Reader字符流读取文件内容---实例

import java.io.*;
public class File4{
    public static void main(String[] args)throws Exception{       //抛出异常,不处理
        File f=new File("e:"+File.separator+"test.txt");        //选择e:test.txt的文件创建对象
        Reader input=new FileReader(f);
        char b[]=new char[(int)f.length()];    //定义一个char数组,数组大小由文件大小决定
        System.out.println("数组长度为:"+input.read(b));  //读取数组内容到b数组中,并返回数组长度
        System.out.println(new String(b));   //将char类型b数组强制转换为String类型            
        input.close();                    //关闭数据流
    }
}  

原文地址:https://www.cnblogs.com/l666/p/9129436.html