gpt4 book ai didi

java - Properties.load会关闭InputStream吗?

转载 作者:行者123 更新时间:2023-12-03 02:58:30 26 4
gpt4 key购买 nike

我看到了this example ,并且我没有看到在 InputStream 上调用 close() 方法,那么 prop.load() 会自动关闭流吗?还是示例中存在错误?

最佳答案

Properties.load()后Stream没有关闭

public static void main(String[] args) throws IOException {

InputStream in = new FileInputStream(new File("abc.properties"));

new Properties().load(in);

System.out.println(in.read());
}

上面的代码返回“-1”,因此流没有关闭。否则它应该抛出 java.io.IOException: Stream Closed

关于java - Properties.load会关闭InputStream吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40078141/

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