0
点赞
收藏
分享

微信扫一扫

FileReader 字节输入流

public class FileReaderTest {
    public static void main(String[] args) {
        Reader fr=null;
        try{
            //2.实例化FileReader对象
            fr =new FileReader("D:\\doc\\诗词.txt");
            char[] ch= new char[1024];//创建字符数组为转储容器
            int len=0;//保存实际储存字符数
            //3.循环读取数据
            while((len=fr.read(ch))>0){
                System.out.println(new String(ch,0,len));
            }
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }finally {
            if (fr!=null){
                try{
                    fr.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }
}

 



举报

相关推荐

0 条评论