java 一行一行读取文件
原创    ms_eye    发表于:2018-04-08 16:20:10
  阅读 :82   收藏   编辑
package com.xx;

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

public class Tmp {

    public static void main(String[] args){

        FileReader in = null;
        try {
            in = new FileReader("D:/test.txt");
        } catch (FileNotFoundException e1) {
            e1.printStackTrace();
        }
        BufferedReader  bin = new BufferedReader (in);
        String  line = null;
        try {
            //readLine() 一行一行的读取
            while((line = bin.readLine()) != null) {
                String tmp = line;
                System.err.println(tmp);
            }
        } catch (IOException e1) {
            e1.printStackTrace();
        }
        try {
            bin.close();
            in.close();
        } catch (Exception e) {
        }

    }
}
评论
条评论