{"id":4090,"date":"2019-04-06T20:46:18","date_gmt":"2019-04-06T12:46:18","guid":{"rendered":"http:\/\/www.xttblog.com\/?p=4090"},"modified":"2019-04-06T20:46:18","modified_gmt":"2019-04-06T12:46:18","slug":"%e4%b8%ba%e4%bb%80%e4%b9%88fileinputstream%e3%80%81fileoutputstream%e7%ad%89%e4%b8%ad%e7%9a%84finalize%e6%96%b9%e6%b3%95%e9%80%90%e6%b8%90%e8%a2%ab%e7%a7%bb%e9%99%a4%e4%ba%86%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/www.xttblog.com\/?p=4090","title":{"rendered":"\u4e3a\u4ec0\u4e48FileInputStream\u3001FileOutputStream\u7b49\u4e2d\u7684finalize\u65b9\u6cd5\u9010\u6e10\u88ab\u79fb\u9664\u4e86\uff1f"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">\u8fd9\u4e24\u5929\u8fc7\u8282\u653e\u5047\uff0c\u5230\u54ea\u90fd\u662f\u4eba\u5c71\u4eba\u6d77\u3002\u672c\u6587\u6211\u662f\u6253\u7b97\u51fa\u53bb\u8dd1\u8dd1\u7684\uff0c\u4f46\u662f\u5948\u4f55\u5c0f\u5b69\u6709\u8bfe\u8981\u4e0a\uff0c\u6240\u4ee5\u6700\u7ec8\u5c31\u53bb\u4e0a\u6d77\u4ea4\u5927\u8f6c\u4e86\u8f6c\u3002\u7ed3\u679c\u4ea4\u5927\u4e5f\u662f\u4eba\u6ee1\u4e3a\u60a3\u3002\u5230\u5904\u90fd\u662f\u4eba\uff0c\u8f66\u8fdb\u53bb\u90fd\u80fd\u5835\u5341\u51e0\u5206\u949f\u3002 <\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u5728\u4ea4\u5927\u73a9\u7684\u7a7a\u95f2\u65f6\u95f4\uff0c\u6211\u6536\u5230\u77e5\u4e4e\u4e0a\u4e00\u4e2a\u63a8\u9001\u3002\u6709\u4eba\u95ee\u6211\uff0c\u4e3a\u4ec0\u4e48FileInputStream\u3001FileOutputStream\u7b49\u4e2d\u7684finalize\u65b9\u6cd5\u9010\u6e10\u88ab\u79fb\u9664\u4e86\uff1f <\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/images.weserv.nl\/?url=https:\/\/wx1.sinaimg.cn\/large\/8fa5dcfcly1g1t75ozov6j20h0040aar.jpg\" alt=\"\" \/><figcaption>JDK12 \u79fb\u9664finalize\u65b9\u6cd5<\/figcaption><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">\u8bf4\u5b9e\u8bdd\uff0c\u6211\u4e4b\u524d\u53ea\u662f\u4e86\u89e3\u5230\uff0cfinalize \u65b9\u6cd5\u88ab\u79fb\u9664\u4e86\uff0c\u4f46\u662f\u5e76\u6ca1\u6709\u6df1\u7a76\u5b83\u4e3a\u4ec0\u4e48\u88ab\u79fb\u9664\u4e86\u3002 <\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u6240\u4ee5\uff0c\u5bf9\u4e8e\u8fd9\u4e2a\u95ee\u9898\uff0c\u6211\u4e5f\u67e5\u9605\u4e86\u4e00\u4e9b\u7f51\u4e0a\u7684\u8d44\u6599\uff0c\u7ed3\u679c\u6ca1\u4ec0\u4e48\u7b54\u6848\u6765\u63cf\u8ff0\u8fd9\u4e2a\u95ee\u9898\u3002JDK \u5b98\u65b9\u89e3\u91ca\u7684\u4e5f\u5f88\u7b80\u5355\uff0c\u5927\u6982\u610f\u601d\u5c31\u662f\u8bf4\u4ece JDK9 \u5f00\u59cb finalize \u5c31\u88ab\u5f03\u7528\u4e86\uff0cJava \u63a8\u8350\u4f7f\u7528\u65b9\u5f0f\u662f\u5173\u95ed\u6587\u4ef6\u7684\u65b9\u6cd5\u662f\u663e\u5f0f\u8c03\u7528 close \u6216\u4f7f\u7528 try-with-resources\u3002 <\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/images.weserv.nl\/?url=https:\/\/wx1.sinaimg.cn\/large\/8fa5dcfcly1g1t77wlyxqj20fc04njst.jpg\" alt=\"\" \/><figcaption>\u79fb\u9664FileInputStream\u3001FileOutputStream\u3001Java.util.ZipFile\/Inflator\/Deflator\u7684finalize\u65b9\u6cd5<\/figcaption><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">\u6211\u8fd9\u91cc\u5927\u80c6\u7684\u5927\u8138\u4e00\u4e0b\uff0c\u8bf4\u4e00\u4e0b finalize \u65b9\u6cd5\u4e3a\u4ec0\u4e48\u88ab\u79fb\u9664\u3002 <\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u7b2c\u4e00\u4e2a\uff0c\u8fd9\u4e2a\u65b9\u6cd5\uff0c\u6211\u4eec\u786e\u5b9e\u7528\u7684\u4e0d\u591a\uff0c\u7559\u7740\u5f88\u9e21\u808b\u3002 <\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u7b2c\u4e8c\u4e2a\uff0cfinalize \u65b9\u6cd5\u5f88\u5371\u9669\uff0c\u6216\u8005\u8bf4\u7528\u4e0d\u597d\u5b83\u5f88\u5371\u9669\u3002 <\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u7b2c\u4e09\u4e2a\uff0c\u4ece\u6027\u80fd\u4e0a\u6765\u8bf4\uff0cfinalize \u65b9\u6cd5\u5f71\u54cd GC \u6027\u80fd\u3002\u8fd9\u4e00\u70b9\u53ef\u4ee5\u4ece\u5404\u79cd NIO \u6846\u67b6\u4e2d\u7684 direct memory \u7684\u91ca\u653e\u5e76\u4e0d\u662f\u901a\u8fc7 finalize() \u6765\u611f\u53d7\u3002 <br><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u7b2c\u56db\u4e2a\uff0c\u4ece JDK9 \u5f00\u59cb\uff0c\u6709\u4e86\u66f4\u597d\u7684\u00a0Cleaner \u673a\u5236\u3002\u8fd9\u6837\u00a0try-with-resources \u5c31\u663e\u5f97\u7528\u8d77\u6765\u5f88\u65b9\u4fbf\u3002 <br><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u7b2c\u4e94\u4e2a\uff0c\u6211\u4eec\u5728\u4ec0\u4e48\u65f6\u5019\u53bb\u8c03\u7528 close \u65b9\u6cd5\u5e94\u8be5\u662f\u5f88\u660e\u786e\u7684\u3002\u5982\u679c\u901a\u8fc7\u00a0finalize \u65b9\u6cd5\u53bb\u5173\u95ed\u6d41\u7684\u8bdd\uff0c\u5f88\u5bb9\u6613\u9020\u6210\u9057\u6f0f\u5173\u95ed\u6d41\u7684\u60c5\u51b5\u3002 <br><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u53e6\u5916\uff0cZipFile\/Inflator\/Deflator \u4e2d\u7684 finalize \u65b9\u6cd5\u4e5f\u88ab\u5220\u9664\u4e86\u3002 <br><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u6211\u76f8\u4fe1 Java \u5185\u90e8\u5e94\u8be5\u6709\u4e00\u4e2a\u5404 API \u8c03\u7528\u7684\u4e00\u4e2a\u6307\u6807\uff0c\u81f3\u5c11\u662f\u53ef\u4ee5\u4ece\u5404\u5f00\u53d1\u8005\u6216\u8005\u5f00\u6e90\u9879\u76ee\u4e2d\uff0c\u83b7\u53d6\u5230\u8fd9\u4e2a\u6307\u6807\u3002finalize \u65b9\u6cd5\uff0c\u4f7f\u7528\u7684\u4eba\u592a\u5c11\u4e86\uff0c\u800c\u4e14\u8fd8\u4e0d\u5b89\u5168\u3002\u6ca1\u5fc5\u8981\u8fd8\u8ba9\u5b83\u5b58\u5728\u4e8e Java \u4e4b\u4e2d\uff0c\u5c31\u662f\u4f60\u60f3\u7528\u8fd9\u4e2a\u65b9\u6cd5\uff0c\u4e5f\u53ef\u4ee5\u81ea\u5df1\u7b80\u5355\u7684\u53bb\u5b9e\u73b0\u4e00\u4e2a\u7c7b\u4f3c\u7684\u65b9\u6cd5\u3002 <\/p>\n<!-- <audio autoplay=\"autoplay\" height=\"100\" width=\"100\" hidden=\"true\"><source src=\"https:\/\/c.coka.la\/orAvPR.mp3\" type=\"audio\/mp3\"\/><\/audio><img decoding=\"async\" src=\"https:\/\/images.weserv.nl\/?url=https:\/\/ws3.sinaimg.cn\/large\/8fa5dcfcgy1g4em3rzar5j20ib089ae0.jpg\" alt=\"\u4e1a\u4f59\u8349\u516c\u4f17\u53f7\"\/> --><p><!-- <img decoding=\"async\" src=\"https:\/\/raw.githubusercontent.com\/xmt1139057136\/xttblog\/master\/8fa5dcfcgy1g4em3rzar5j20ib089ae0.jpg\" alt=\"\u4e1a\u4f59\u8349\u516c\u4f17\u53f7\"\/>--><img decoding=\"async\" src=\"https:\/\/saas.51autoparts.cn\/api\/admin\/sys-file\/oss\/file?fileName=84db51f8561e448f9a4fda2eff0811f9.jpg\" alt=\"\u4e1a\u4f59\u8349\u516c\u4f17\u53f7\"\/><\/p><p>\u6700\u540e\uff0c\u6b22\u8fce\u5173\u6ce8\u6211\u7684\u4e2a\u4eba\u5fae\u4fe1\u516c\u4f17\u53f7\uff1a\u4e1a\u4f59\u8349\uff08yyucao\uff09\uff01<b>\u53ef\u52a0\u4f5c\u8005\u5fae\u4fe1\u53f7\uff1a<font color=\"red\">xttblog2<\/font>\u3002\u5907\u6ce8\uff1a\u201c1\u201d\uff0c\u6dfb\u52a0\u535a\u4e3b\u5fae\u4fe1\u62c9\u4f60\u8fdb\u5fae\u4fe1\u7fa4\u3002\u5907\u6ce8\u9519\u8bef\u4e0d\u4f1a\u540c\u610f\u597d\u53cb\u7533\u8bf7\u3002<\/b>\u518d\u6b21\u611f\u8c22\u60a8\u7684\u5173\u6ce8\uff01\u540e\u7eed\u6709\u7cbe\u5f69\u5185\u5bb9\u4f1a\u7b2c\u4e00\u65f6\u95f4\u53d1\u7ed9\u60a8\uff01\u539f\u521b\u6587\u7ae0\u6295\u7a3f\u8bf7\u53d1\u9001\u81f3532009913@qq.com\u90ae\u7bb1\u3002\u5546\u52a1\u5408\u4f5c\u4e5f\u53ef\u6dfb\u52a0\u4f5c\u8005\u5fae\u4fe1\u8fdb\u884c\u8054\u7cfb\uff01<\/p><p>\u672c\u6587\u539f\u6587\u51fa\u5904\uff1a<a href=\"https:\/\/www.xttblog.com\">\u4e1a\u4f59\u8349<\/a>\uff1a &raquo; <a href=\"https:\/\/www.xttblog.com\/?p=4090\">\u4e3a\u4ec0\u4e48FileInputStream\u3001FileOutputStream\u7b49\u4e2d\u7684finalize\u65b9\u6cd5\u9010\u6e10\u88ab\u79fb\u9664\u4e86\uff1f<\/a><\/p><!-- <div class=\"bd-reward-stl\"><button id=\"bdRewardBtn\"><span><\/span><\/button><\/div> -->","protected":false},"excerpt":{"rendered":"<p>\u8fd9\u4e24\u5929\u8fc7\u8282\u653e\u5047\uff0c\u5230\u54ea\u90fd\u662f\u4eba\u5c71\u4eba\u6d77\u3002\u672c\u6587\u6211\u662f\u6253\u7b97\u51fa\u53bb\u8dd1\u8dd1\u7684\uff0c\u4f46\u662f\u5948\u4f55\u5c0f\u5b69\u6709\u8bfe\u8981\u4e0a\uff0c\u6240\u4ee5\u6700\u7ec8\u5c31\u53bb\u4e0a\u6d77\u4ea4\u5927\u8f6c\u4e86\u8f6c\u3002\u7ed3 [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[1956,900,615,1322,74],"class_list":["post-4090","post","type-post","status-publish","format-standard","hentry","category-java","tag-deflator","tag-fileinput-js","tag-jdk1-7","tag-jszip","tag-zip"],"_links":{"self":[{"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/posts\/4090","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=4090"}],"version-history":[{"count":1,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/posts\/4090\/revisions"}],"predecessor-version":[{"id":4091,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/posts\/4090\/revisions\/4091"}],"wp:attachment":[{"href":"https:\/\/www.xttblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=4090"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=4090"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=4090"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}