java - Common way to use System.in several times without closing -


i have console menu has read inputs few times in different methods. use new bufferedreader(new inputstreamreader(system.in)) that. if reader closed in method it's not useable/openable again because of system.in.

to solve problem 1 possibility static bufferedreader br = new bufferedreader(new inputstreamreader(system.in)); it's usable several times in different methods main.br.readline();.

is way or there better methods?

pass bufferedreader method(s) (or make shared field), way don't have re-create it. also, correct closing system.in (or wrapping system.in) cause issues. instead of

public void foo() 

something like

public void foo(bufferedreader reader) 

Comments

Popular posts from this blog

python 3 IndexError: list index out of range -

android - How to save instance state of selected radiobutton on menu -

IF statement in MySQL trigger -