s***1 发帖数: 49 | 1 i have a program like this, when the statement "reader.getLine()" in my main
method is run, it gives the error "Stream closed". Why????
I have a function that has a local bufferedreader that I need, and I close
that local reader because it is "cleaner" this way. Then when I return to my
main program, I have a separate bufferedReader, with seperate instantiation
, but the program does not seem to "separate" them? Any explanations? What
should I do to correct it?
public static void main() throws | z***h 发帖数: 405 | 2 when you hit enter in localFunction, localReader.close() will close your
standard input.
comment it out, it should work.
main
my
instantiation
【在 s***1 的大作中提到】 : i have a program like this, when the statement "reader.getLine()" in my main : method is run, it gives the error "Stream closed". Why???? : I have a function that has a local bufferedreader that I need, and I close : that local reader because it is "cleaner" this way. Then when I return to my : main program, I have a separate bufferedReader, with seperate instantiation : , but the program does not seem to "separate" them? Any explanations? What : should I do to correct it? : public static void main() throws
| s***1 发帖数: 49 | 3 If I don't close it in the localFunction, is it not dangerous?
Also, are you saying if I close the standard input once in a flow of a
program, I can never "re-open" it?
【在 z***h 的大作中提到】 : when you hit enter in localFunction, localReader.close() will close your : standard input. : comment it out, it should work. : : main : my : instantiation
| c*****t 发帖数: 1879 | 4 1. you should not close System.in
2. there is a potential problem using two separate bufferedreader on
the same input stream. You will miss some characters (i.e. buffered
in one reader, and not seen in the other reader).
why don't you just share the buffered reader? the fundamental problem
is your design.
【在 s***1 的大作中提到】 : If I don't close it in the localFunction, is it not dangerous? : Also, are you saying if I close the standard input once in a flow of a : program, I can never "re-open" it?
| s***1 发帖数: 49 | 5 ok thanks.
【在 c*****t 的大作中提到】 : 1. you should not close System.in : 2. there is a potential problem using two separate bufferedreader on : the same input stream. You will miss some characters (i.e. buffered : in one reader, and not seen in the other reader). : why don't you just share the buffered reader? the fundamental problem : is your design.
|
|