Do I need to close an InputStream in Java?

后端 未结 2 1206
长发绾君心
长发绾君心 2021-01-01 08:30

My code is:

InputStream confFile=classLoader.getResourceAsStream(\"myconffile.properties\");

In docs:

The close meth

2条回答
  •  误落风尘
    2021-01-01 08:58

    You do need to close the input Stream, because the stream returned by the method you mention is actually FileInputStream or some other subclass of InputStream that holds a handle for a file. If you do not close this stream you have resource leakage.

提交回复
热议问题