错误/流在BufferedReader中关闭

时间:2016-03-18 04:54:35

标签: java loops bufferedreader file-handling

我的程序中有这个方法:

public void View() throws IOException{
        File original=new File("C:\\voters.txt");
        BufferedReader read=new BufferedReader(new FileReader(original));

        vNum=JOptionPane.showInputDialog("Enter voters ID: ");
        String line;
        while((line=read.readLine())!=null){

            String info[]=line.split("/");

            if(info[1].matches(vNum)){
                all="\t\t\t\t-------VOTERS INFORMATION-------\t\t\t\t\n\n"
                        +"NAME: "+info[2]+"\tAGE: "+info[3]
                        +"\nGENDER: "+info[4]+"DATE OF BIRTH: "+info[5]
                        +"\nPLACE OF BIRTH: "+info[6]+"\tPLACE OF BIRTH: "+info[7]
                        +"\nCIVIL STATUS: "+info[8]+"\tCITIZENSHIP: "+info[9]
                        +"\nPROFESSION/OCCUPATION: "+info[10]+"\tVOTERS NUMBER: "+info[1]
                        +"\nFATHER'S NAME: "+info[11]+"\nMOTHER'S NAME: "+info[12];

                JOptionPane.showMessageDialog(null, new JTextArea(all));
                break;
            }

            else{
                JOptionPane.showMessageDialog(null, "Voter doesn't exit");
            }

            read.close();
        }
    }

但是随着时间的推移我执行此方法,它始终会停止并出现错误。它说Stream关闭了。这是它:

Exception in thread "main" java.io.IOException: Stream closed
    at java.io.BufferedReader.ensureOpen(Unknown Source)
    at java.io.BufferedReader.readLine(Unknown Source)
    at java.io.BufferedReader.readLine(Unknown Source)
    at lozada.My_Voting_System_Official.View(My_Voting_System_Official.java:231)
    at lozada.My_Voting_System_Official.Menu(My_Voting_System_Official.java:73)
    at lozada.My_Voting_System_Official.main(My_Voting_System_Official.java:26)

我真的不知道是什么问题,因为我的程序中的大多数方法都有while((line=read.readLine())!=null),并且这些方法有效。只有这种方法不起作用。此外,文本文件存在。请帮忙

0 个答案:

没有答案