zoukankan      html  css  js  c++  java
  • 文本文件读取

    读取文本文件

    1. 关联文件,使用Reader 和 FileReader

    2. 创建缓冲 char数组,用于接收读取到的文本信息

    3. 将文本读入到 缓冲数组(buff)中

    4. 输出读取到的文本信息

    5. 关闭文件读入流

    package com.machuang.io.charIO;
    
    import java.io.FileNotFoundException;
    import java.io.FileReader;
    import java.io.IOException;
    import java.io.Reader;
    
    public class textRead {
    
        public static void main(String[] args) {
            // 与文件建立联系
            Reader reader = null;
            
        
            try {
                reader = new FileReader("F:/win10/test/a.txt");
                
                // 创建接收读取内容的 char数组
                char[] cbuf = new char[1024];
                int len = 0;
                
                // 读取
                while(-1 != (len = reader.read(cbuf))) {
                    System.out.println(new String(cbuf, 0, len));
                }
                
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            } finally {
                if(null != reader) {
                    try {
                        reader.close();
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }
                    
            }
            
    
        }    // match main function
    
    }
  • 相关阅读:
    window.onresize绑定事件以及解绑事件
    jqGrid中select带可编辑的
    ROS(机器视觉)
    Python(time模块)
    Python(random模块)
    Python迭代器
    Python生成器
    Python装饰器(函数)
    ROS(URDF机器人建模)
    ROS基础
  • 原文地址:https://www.cnblogs.com/cappuccinom/p/8809738.html
Copyright © 2011-2022 走看看