java - I/O流在超出作用域后是否是安全的
PHP中文网
PHP中文网 2017-04-17 17:44:53
0
2
319

在程序中使用如下代码是否是安全的

properties.load(new FileInputStream("src/main/resource/jdbc.properties"));

直接 new 对象的形式作为方法参数传递,当 load 方法执行完后,作为方法参数的 FileInputStream 并没有办法显示的关闭,这种等待对象超出作用域等待自动释放的方法是否是安全的?

PHP中文网
PHP中文网

认证0级讲师

reply all(2)
左手右手慢动作

Safety is safe, but this way of using resources is not recommended. Unused resources should be released immediately.

刘奇

It has nothing to do with security. If you don’t close it after use, it will cause a lot of memory garbage. Although Java will automatically collect it, it will overall increase the burden on the system

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template