E
Eric Capps
I'm using BufferedReader with a URL to try to read information from that
URL and do something with it. The BufferedReader is basically declared
as follows:
InputStreamReader stream = new InputStreamReader((new
URL(url)).openStream());
BufferedReader fileReader = new BufferedReader(stream);
There are a certain number of lines "length" I'm expecting in the file.
I then read from the BufferedReader as follows:
while(fileReader.ready() && i < length){
String thisLine = fileReader.readLine();
// code i've snipped out involving thisLine
i++;
}
I have simplified this, but you get the idea: I am using readLine() and
the doing something with that line.
The problem: sometimes, this loop seems to terminate earlier than I am
expecting, that is, before "length" number of lines have been read. When
I debug the code, and step through, this NEVER happens, and it only
sometimes happens (and not always on the same invocations) when I
actually run it.
I suspect that what is happening is that somehow the ready() method of
the BufferedReader is returning false prematurely. My questions:
1) Is it possible that the BufferedReader is somehow not able to read
the entire contents of the URL, thus terminating before I expect it to?
2) If so, why is this happening, and how can I work around this?
URL and do something with it. The BufferedReader is basically declared
as follows:
InputStreamReader stream = new InputStreamReader((new
URL(url)).openStream());
BufferedReader fileReader = new BufferedReader(stream);
There are a certain number of lines "length" I'm expecting in the file.
I then read from the BufferedReader as follows:
while(fileReader.ready() && i < length){
String thisLine = fileReader.readLine();
// code i've snipped out involving thisLine
i++;
}
I have simplified this, but you get the idea: I am using readLine() and
the doing something with that line.
The problem: sometimes, this loop seems to terminate earlier than I am
expecting, that is, before "length" number of lines have been read. When
I debug the code, and step through, this NEVER happens, and it only
sometimes happens (and not always on the same invocations) when I
actually run it.
I suspect that what is happening is that somehow the ready() method of
the BufferedReader is returning false prematurely. My questions:
1) Is it possible that the BufferedReader is somehow not able to read
the entire contents of the URL, thus terminating before I expect it to?
2) If so, why is this happening, and how can I work around this?