根據StAX XMLEventReader,XMLEventWriter,XMLStreamReader,XMLStreamWriter API close()方法不會關閉uderlying資源。因此,此代碼爲什麼StAX讀者和作者不關閉底層輸入源?
XMLInputFactory xf = XMLInputFactory.newInstance();
XMLStreamReader xr = xf.createXMLStreamReader(new FileInputStream("1.xml"));
...
xr.close();
看起來安全乍一看導致資源泄漏。
有沒有人知道一個用例,當不關閉底層資源可能會有用?
因爲這是他們設計的方式。不建設性。 – EJP 2013-05-11 07:52:06
相關問題:http://stackoverflow.com/questions/38634442/why-do-stax-readers-and-writers-not-implement-closeable – Roland 2016-07-28 11:02:19