@Eray Tuncer 行の読み取りを開始する前であれば、接続がいつ閉じられたかによって異なります。そうであれば、例外が発生するはずです。しかし、読み取りの間にある場合は、ストリームの終わりを示す「null」が表示されると思います。BufferedReader からの readLine の次の実装を確認してください。
String readLine(boolean ignoreLF) throws IOException { StringBuffer s = null; int startChar;
synchronized (lock) {
ensureOpen(); //This method ensures that the stream is open and this is called before start reading
................... ................ //----接続が閉じられた場合、読み取り操作が開始されましたnull を返すだけです--------- bufferLoop: for (;;) {
if (nextChar >= nChars)
fill();
if (nextChar >= nChars) { /* EOF */
if (s != null && s.length() > 0)
return s.toString();
else
return null;
}
boolean eol = false;
char c = 0;
int i;
/* Skip a leftover '\n', if necessary */
if (omitLF && (cb[nextChar] == '\n'))
nextChar++;
skipLF = false;
omitLF = false;
charLoop:
for (i = nextChar; i < nChars; i++) {
c = cb[i];
if ((c == '\n') || (c == '\r')) {
eol = true;
break charLoop;
}
}
startChar = nextChar;
nextChar = i;
if (eol) {
String str;
if (s == null) {
str = new String(cb, startChar, i - startChar);
} else {
s.append(cb, startChar, i - startChar);
str = s.toString();
}
nextChar++;
if (c == '\r') {
skipLF = true;
}
return str;
}
if (s == null)
s = new StringBuffer(defaultExpectedLineLength);
s.append(cb, startChar, i - startChar);
}
}
}
したがって、肝心なのは、IOException に依存するのではなく、この操作で null をチェックする必要があるということです。問題の解決に役立つことを願っています。ありがとうございました !