具有缓冲读取线的Nullpointer异常

时间:2017-03-25 13:17:56

标签: java nullpointerexception null bufferedreader

我一直试图读取这个文件的行,然后将它们保存到数组中,但是当我尝试打印这些行来尝试它时,它的行上有一个nullpointer:

while( (line = br.readLine()) !=null

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

public class Main1 {

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        String line;
        BufferedReader br = null ;
        try {
            new BufferedReader(new FileReader("/Users/Daniq/Desktop/eda/pruebaEda.txt"));
            System.out.println("Done");

            try {
                while( (line = br.readLine()) != null){
                    System.out.println(line);
                }
            } catch (IOException e) {
                // TODO Auto-generated catch block
                System.out.println("error ");
            }

        } catch(FileNotFoundException fnfex){
            System.out.println("File not found");
        }

    }

}

1 个答案:

答案 0 :(得分:1)

尝试之后,你不会将br引用推荐为

br = new BufferedReader...