26

你是否还在写try-catch-finally?来使用try-with-resources优雅地关闭流吧

 4 years ago
source link: https://juejin.im/post/5d14d92ef265da1b7004bbd6
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
前言 开发中,我们常常需要在最后进行一些资源的关闭。比如读写文件流等,常见的,我们会在最后的finally里进行资源的关闭。但是这种写法是很不简洁的。其实,早在JDK1.7就已经引入了try-with-resources来关闭资源的方式,我们今天就来体验一下t

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK