Many people asked question like that but this one is a little bit different. Here is the code:
public static BufferedReader reader;
public static String read
Because System.in
is same Object
(public final static InputStream in;
of System
class) both method calls are using, closing in one method will automatically close System.in
for other method. You should close the BufferedReader
from outside(as I can see it's public
) the method once you finish calling readString
and so it will ultimately close underlying System.in
.