readline()读取数据

package com.io;

import java.io.BufferedReader;  
import java.io.FileNotFoundException;  
import java.io.FileReader;  
import java.io.IOException; 

 public class testdoc {
       public static void main(String[] args) {  
            BufferedReader bufr = null;  
            try {  
                //创建一个字符读取流对象和文件相关联。  
                FileReader fr = new FileReader("aaa.txt");  
                //为了提高效率。加入缓冲技术。将字符读取流对象作为参数传递给缓冲对象的构造函数。  
                bufr = new BufferedReader(fr);  
                String line;  
                try {  
                    while ((line = bufr.readLine()) != null) {  
                        System.out.println(line+"-");  

                    }  
                } catch (IOException e) {  
                    System.out.println(e.getMessage());  
                }  
            } catch (FileNotFoundException e) {  
                System.out.println(e.getMessage());  
            } finally {  
                if (bufr != null) {  
                    try {  
                        bufr.close();  
                    } catch (IOException e) {  
                        System.out.println(e.getMessage());  
                    }  
                }  
            }  


        } 
 }

这里写图片描述

猜你喜欢

转载自blog.csdn.net/qq_36306340/article/details/79378004