I'm having a problem reading lines from a text file. The reading in itself works fine, but when the application has read 545 lines of text (545 .readLine()'s) I get a read error exception, for no reason at all as far as I can see.

The code for the reading looks as follows:

public String readISBN() throws IOException
        String ISBN = "";
        ISBN = br.readLine();

        return ISBN;

The inputstream, bufferedreader etc is created by:

public FileHandler() throws FileNotFoundException, IOException
        fstream = new FileInputStream("ISBN.txt");
        out = new BufferedWriter(new FileWriter("Result.txt"));
        dataIn = new DataInputStream(fstream);
        br = new BufferedReader(new  InputStreamReader(dataIn));

Error report:

Exception in thread "main" java.io.IOException: Read error
at java.io.FileInputStream.readBytes(Native Method)
at java.io.FileInputStream.read(FileInputStream.java:199)
at java.io.DataInputStream.read(DataInputStream.java:132)
at sun.nio.cs.StreamDecoder.readBytes(StreamDecoder.java:264)
at sun.nio.cs.StreamDecoder.implRead(StreamDecoder.java:306)
at sun.nio.cs.StreamDecoder.read(StreamDecoder.java:158)
at java.io.InputStreamReader.read(InputStreamReader.java:167)
at java.io.BufferedReader.fill(BufferedReader.java:136)
at java.io.BufferedReader.readLine(BufferedReader.java:299)
at java.io.BufferedReader.readLine(BufferedReader.java:362)
at Parser.FileHandler.readISBN(FileHandler.java:44)

So what I'm wondering is if anyone can see what the problem is, or what I can do to handle the exception.


This article has been dead for over six months. Start a new discussion instead.