“java.io.IOException: Stream closed” with new BufferedReader

前端 未结 2 1641
醉话见心
醉话见心 2021-01-29 05:40

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         


        
2条回答
  •  长情又很酷
    2021-01-29 06:05

    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.

提交回复
热议问题