zoukankan      html  css  js  c++  java
  • FileReader输入文本流

    FileReader案例:

    package com.javaSe.FileReader;
    
    
    import java.io.FileNotFoundException;
    import java.io.FileReader;
    import java.io.IOException;
    
    
    /*
    FileReader:
        文件字符输入流,只能读取普通文本。
        读取文本内容时,比较方便,快捷。
    */
    public class FileReaderTest01 {
        public static void main(String[] args) {
            FileReader fr = null;
            try {
                // 创建文件输入流
                fr = new FileReader("tempFile");
                // 准备一个char数组
                char[] chars = new char[4];
                // 往char数组中毒
                fr.read(chars);// 按照字符的方式读取:第一次a,第二次b,第三次c,第四次b
                for (char c : chars){
                    System.out.print(c);
                }
                
                /*// 开始读
                char[] chars = new char[4];// 一次读取4个字符
                int readCount = 0;
                while ((readCount = fr.read(chars)) != -1){
                    System.out.print(new String(chars,0,readCount));
                }*/
                
                
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            } finally {
                if (fr != null) {
                    try {
                        fr.close();
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }
            }
        }
    }
  • 相关阅读:
    coder的脚印
    Mysql
    MSDos
    Windows Develop
    Eclipse 使用总结
    DBA常用SQL
    SSH总结
    Unity3D协程
    yield的作用
    UGUI优化
  • 原文地址:https://www.cnblogs.com/xlwu/p/13466103.html
Copyright © 2011-2022 走看看