gpt4 book ai didi

file-io - Groovy XmlParser -> 需要关闭吗?

转载 作者:行者123 更新时间:2023-12-04 04:59:53 27 4
gpt4 key购买 nike

我正在使用 groovy XmlParser 读取 xml- 文件,例如:

def myXMLContent = new XmlParser().parse(new File("myFile.xml"))

但是我没有找到 XmlParser 的 close 方法。我不必释放文件句柄吗?我在文档中没有找到任何关于此的内容。

最佳答案

不,groovy wraps the file喜欢 new InputSource(new FileInputStream(file)) ,并将其传递给解析器。

正如它在 API docs for InputSource 中所说的那样:

...standard processing of both byte and character streams is to close them on as part of end-of-parse cleanup, so applications should not attempt to re-use such streams after they have been handed to a parser.

关于file-io - Groovy XmlParser -> 需要关闭吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16267870/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com