Redian新闻
>
关于 BufferedReader 问题
avatar
关于 BufferedReader 问题# Java - 爪哇娇娃
s*1
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
avatar
z*h
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

avatar
s*1
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

avatar
c*t
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?

avatar
s*1
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.

相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。