{"id":51356,"date":"2025-08-10T21:44:20","date_gmt":"2025-08-10T13:44:20","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/51356.html"},"modified":"2025-08-10T21:44:20","modified_gmt":"2025-08-10T13:44:20","slug":"java%e6%96%87%e4%bb%b6%e6%93%8d%e4%bd%9c%e4%b8%8eio%e6%b5%81%e6%a0%b8%e5%bf%83%e6%8a%80%e6%9c%af%e8%a7%a3%e6%9e%90","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/51356.html","title":{"rendered":"Java\u6587\u4ef6\u64cd\u4f5c\u4e0eIO\u6d41\u6838\u5fc3\u6280\u672f\u89e3\u6790"},"content":{"rendered":"<p>\u6458\u8981&#xff1a;\u672c\u6587\u7cfb\u7edf\u8bb2\u89e3Java\u6587\u4ef6\u64cd\u4f5c\u7684\u6838\u5fc3\u7c7bFile\u53caIO\u6d41\u4f53\u7cfb&#xff0c;\u901a\u8fc7\u5b9e\u4f8b\u4ee3\u7801\u6f14\u793a\u6587\u4ef6\u521b\u5efa\u3001\u8bfb\u5199\u64cd\u4f5c\u4e0e\u8d44\u6e90\u7ba1\u7406\u7684\u6700\u4f73\u5b9e\u8df5\u3002<\/p>\n<hr \/>\n<h5>\u4e00\u3001File\u7c7b&#xff1a;\u6587\u4ef6\u7cfb\u7edf\u62bd\u8c61\u8868\u793a<\/h5>\n<li>\n<p>\u6838\u5fc3\u529f\u80fd<\/p>\n<p>\/\/ \u6587\u4ef6\u521b\u5efa\u793a\u4f8b<br \/>\nFile file &#061; new File(&#034;data\/config.ini&#034;);<br \/>\nif (!file.exists()) {<br \/>\n\u00a0 \u00a0 file.createNewFile(); \u00a0\/\/ \u53ef\u80fd\u629b\u51faIOException<br \/>\n}<\/p>\n<ul>\n<li>\n<p>\u8868\u793a\u6587\u4ef6\/\u76ee\u5f55\u8def\u5f84\u7684\u62bd\u8c61<\/p>\n<\/li>\n<li>\n<p>\u4e0d\u8981\u6c42\u8def\u5f84\u5b9e\u9645\u5b58\u5728&#xff08;\u9700\u663e\u5f0f\u521b\u5efa&#xff09;<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>\u5173\u952e\u64cd\u4f5c<\/p>\n<table>\n<tr>\n<p>\u65b9\u6cd5<\/p>\n<p>\u529f\u80fd\u8bf4\u660e<\/p>\n<p>\u6ce8\u610f\u4e8b\u9879<\/p>\n<\/tr>\n<tbody>\n<tr>\n<td>createNewFile()<\/td>\n<td>\n<p>\u521b\u5efa\u65b0\u6587\u4ef6<\/p>\n<\/td>\n<td>\n<p>\u9700\u5904\u7406IOException<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>mkdir()<\/td>\n<td>\n<p>\u521b\u5efa\u5355\u7ea7\u76ee\u5f55<\/p>\n<\/td>\n<td>\n<p>\u7236\u76ee\u5f55\u9700\u5b58\u5728<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>delete()<\/td>\n<td>\n<p>\u5220\u9664\u6587\u4ef6\/\u7a7a\u76ee\u5f55<\/p>\n<\/td>\n<td>\n<p>\u975e\u7a7a\u76ee\u5f55\u9700\u9012\u5f52\u5220\u9664<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>renameTo()<\/td>\n<td>\n<p>\u6587\u4ef6\/\u76ee\u5f55\u91cd\u547d\u540d<\/p>\n<\/td>\n<td>\n<p>\u76ee\u6807\u8def\u5f84\u9700\u6709\u6548<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/li>\n<li>\n<p>\u5143\u6570\u636e\u83b7\u53d6<\/p>\n<p>File logFile &#061; new File(&#034;logs\/app.log&#034;);<br \/>\nSystem.out.println(&#034;\u6587\u4ef6\u5927\u5c0f: &#034; &#043; logFile.length() &#043; &#034;\u5b57\u8282&#034;);<br \/>\nSystem.out.println(&#034;\u6700\u540e\u4fee\u6539: &#034; &#043; new Date(logFile.lastModified()));\n<\/li>\n<hr \/>\n<h5>\u4e8c\u3001IO\u6d41\u4f53\u7cfb\u67b6\u6784<\/h5>\n<li>\n<p>\u6d41\u7c7b\u578b\u5bf9\u6bd4<\/p>\n<table>\n<tr>\n<p>\u7c7b\u578b<\/p>\n<p>\u62bd\u8c61\u57fa\u7c7b<\/p>\n<p>\u9002\u7528\u573a\u666f<\/p>\n<p>\u5178\u578b\u5b9e\u73b0\u7c7b<\/p>\n<\/tr>\n<tbody>\n<tr>\n<td>\n<p>\u5b57\u8282\u6d41<\/p>\n<\/td>\n<td>\n<p>InputStream<\/p>\n<\/td>\n<td>\n<p>\u4efb\u610f\u6587\u4ef6\u7c7b\u578b&#xff08;\u5982\u56fe\u7247&#xff09;<\/p>\n<\/td>\n<td>\n<p>FileInputStream<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td><\/td>\n<td>\n<p>OutputStream<\/p>\n<\/td>\n<td><\/td>\n<td>\n<p>FileOutputStream<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p>\u5b57\u7b26\u6d41<\/p>\n<\/td>\n<td>\n<p>Reader<\/p>\n<\/td>\n<td>\n<p>\u6587\u672c\u6587\u4ef6&#xff08;UTF-8\/GBK\u7b49&#xff09;<\/p>\n<\/td>\n<td>\n<p>FileReader<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td><\/td>\n<td>\n<p>Writer<\/p>\n<\/td>\n<td><\/td>\n<td>\n<p>FileWriter<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/li>\n<li>\n<p>\u6d41\u64cd\u4f5c\u6838\u5fc3\u6b65\u9aa4<\/p>\n<p>graph LR<br \/>\n\u00a0 \u00a0 A[\u521b\u5efa\u6d41\u5bf9\u8c61] &#8211;&gt; B[\u6267\u884c\u8bfb\u5199\u64cd\u4f5c]<br \/>\n\u00a0 \u00a0 B &#8211;&gt; C[\u5173\u95ed\u8d44\u6e90]\n<\/li>\n<hr \/>\n<h5>\u4e09\u3001\u6587\u4ef6\u8bfb\u5199\u5b9e\u6218<\/h5>\n<li>\n<p>\u6587\u672c\u6587\u4ef6\u5199\u5165&#xff08;\u5b57\u7b26\u6d41&#xff09;<\/p>\n<p>try (FileWriter writer &#061; new FileWriter(&#034;output.txt&#034;)) {<br \/>\n\u00a0 \u00a0 writer.write(&#034;\u7528\u6237\u64cd\u4f5c\u65e5\u5fd7\u8bb0\u5f55&#034;); \u00a0\/\/ \u81ea\u52a8\u521b\u5efa\u6587\u4ef6<br \/>\n} \u00a0\/\/ try-with-resources\u81ea\u52a8\u5173\u95ed\n<\/li>\n<li>\n<p>\u6587\u672c\u6587\u4ef6\u8bfb\u53d6&#xff08;\u5b57\u7b26\u6d41&#xff09;<\/p>\n<p>try (FileReader reader &#061; new FileReader(&#034;input.txt&#034;)) {<br \/>\n\u00a0 \u00a0 char[] buffer &#061; new char[1024];<br \/>\n\u00a0 \u00a0 int len;<br \/>\n\u00a0 \u00a0 while ((len &#061; reader.read(buffer)) !&#061; -1) {<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0 System.out.print(new String(buffer, 0, len));<br \/>\n\u00a0 \u00a0 }<br \/>\n}\n<\/li>\n<li>\n<p>\u4e8c\u8fdb\u5236\u6587\u4ef6\u5904\u7406&#xff08;\u5b57\u8282\u6d41&#xff09;<\/p>\n<p>\/\/ \u56fe\u7247\u590d\u5236\u793a\u4f8b<br \/>\ntry (FileInputStream in &#061; new FileInputStream(&#034;source.jpg&#034;);<br \/>\n\u00a0 \u00a0 \u00a0FileOutputStream out &#061; new FileOutputStream(&#034;copy.jpg&#034;)) {<br \/>\n\u00a0 \u00a0 \u00a0byte[] buffer &#061; new byte[4096];<br \/>\n\u00a0 \u00a0 \u00a0int bytesRead;<br \/>\n\u00a0 \u00a0 \u00a0while ((bytesRead &#061; in.read(buffer)) !&#061; -1) {<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0out.write(buffer, 0, bytesRead);<br \/>\n\u00a0 \u00a0 \u00a0}<br \/>\n}\n<\/li>\n<hr \/>\n<h5>\u56db\u3001\u6027\u80fd\u4f18\u5316\u6280\u5de7<\/h5>\n<li>\n<p>\u7f13\u51b2\u6d41\u5e94\u7528<\/p>\n<p>\/\/ \u7f13\u51b2\u6d41\u63d0\u5347\u8bfb\u5199\u6548\u7387<br \/>\ntry (BufferedReader br &#061; new BufferedReader(new FileReader(&#034;large.txt&#034;));<br \/>\n\u00a0 \u00a0 \u00a0BufferedWriter bw &#061; new BufferedWriter(new FileWriter(&#034;output.txt&#034;))) {<br \/>\n\u00a0 \u00a0 \u00a0String line;<br \/>\n\u00a0 \u00a0 \u00a0while ((line &#061; br.readLine()) !&#061; null) {<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0bw.write(line);<br \/>\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0bw.newLine();<br \/>\n\u00a0 \u00a0 \u00a0}<br \/>\n}\n<\/li>\n<li>\n<p>\u5927\u6587\u4ef6\u5904\u7406\u5efa\u8bae<\/p>\n<ul>\n<li>\n<p>\u7f13\u51b2\u533a\u5927\u5c0f\u8bbe\u7f6e\u4e3a4KB-8KB&#xff08;\u9002\u914d\u78c1\u76d8\u5757\u5927\u5c0f&#xff09;<\/p>\n<\/li>\n<li>\n<p>\u907f\u514d\u5355\u6b21\u8bfb\u53d6\u8d85\u5927\u6570\u7ec4&#xff08;\u9632\u6b62\u5185\u5b58\u6ea2\u51fa&#xff09;<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<hr \/>\n<h5>\u4e94\u3001\u8d44\u6e90\u7ba1\u7406\u89c4\u8303<\/h5>\n<li>\n<p>\u4f20\u7edf\u5173\u95ed\u65b9\u5f0f\u7f3a\u9677<\/p>\n<p>FileWriter fw &#061; null;<br \/>\ntry {<br \/>\n\u00a0 \u00a0 fw &#061; new FileWriter(&#034;temp.txt&#034;);<br \/>\n\u00a0 \u00a0 fw.write(&#034;\u6d4b\u8bd5&#034;);<br \/>\n} finally {<br \/>\n\u00a0 \u00a0 if (fw !&#061; null) fw.close(); \/\/ \u53ef\u80fd\u9057\u6f0f\u5173\u95ed<br \/>\n}\n<\/li>\n<li>\n<p>try-with-resources\u65b9\u6848&#xff08;Java7&#043;&#xff09;<\/p>\n<p>try (FileOutputStream fos &#061; new FileOutputStream(&#034;data.bin&#034;);<br \/>\n\u00a0 \u00a0 \u00a0ObjectOutputStream oos &#061; new ObjectOutputStream(fos)) {<br \/>\n\u00a0 \u00a0 \u00a0oos.writeInt(1024); \u00a0\/\/ \u81ea\u52a8\u8c03\u7528close()<br \/>\n} catch (IOException e) {<br \/>\n\u00a0 \u00a0 \u00a0e.printStackTrace();<br \/>\n}<\/p>\n<p>\u4f18\u52bf&#xff1a;<\/p>\n<ul>\n<li>\n<p>\u81ea\u52a8\u8c03\u7528AutoCloseable.close()<\/p>\n<\/li>\n<li>\n<p>\u907f\u514d\u8d44\u6e90\u6cc4\u6f0f<\/p>\n<\/li>\n<li>\n<p>\u652f\u6301\u591a\u8d44\u6e90\u58f0\u660e<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<hr \/>\n<h4>\u5173\u952e\u5b9e\u8df5\u603b\u7ed3<\/h4>\n<li>\n<p>\u8def\u5f84\u5904\u7406\u539f\u5219<\/p>\n<ul>\n<li>\n<p>\u4f18\u5148\u4f7f\u7528\u76f8\u5bf9\u8def\u5f84&#xff08;\u9002\u914d\u4e0d\u540c\u73af\u5883&#xff09;<\/p>\n<\/li>\n<li>\n<p>\u89c4\u8303\u5316\u8def\u5f84&#xff1a;file.getCanonicalPath()<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>\u7f16\u7801\u6ce8\u610f\u4e8b\u9879<\/p>\n<ul>\n<li>\u6587\u672c\u64cd\u4f5c\u663e\u5f0f\u6307\u5b9a\u5b57\u7b26\u96c6&#xff1a;\n<p>new OutputStreamWriter(fos, StandardCharsets.UTF_8)\n<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>\u5f02\u5e38\u5904\u7406\u89c4\u8303<\/p>\n<ul>\n<li>\n<p>\u533a\u5206\u68c0\u67e5\u5f02\u5e38&#xff08;\u5982IOException)\u548c\u975e\u68c0\u67e5\u5f02\u5e38<\/p>\n<\/li>\n<li>\n<p>\u5728\u65b9\u6cd5\u7b7e\u540d\u58f0\u660e\u6216\u4f7f\u7528try-catch\u5904\u7406<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<p>\u901a\u8fc7\u5408\u7406\u4f7f\u7528File\u7c7b\u7ba1\u7406\u5143\u6570\u636e&#xff0c;\u914d\u5408\u6070\u5f53\u7684IO\u6d41\u5b9e\u73b0\u8bfb\u5199\u64cd\u4f5c&#xff0c;\u7ed3\u5408try-with-resources\u786e\u4fdd\u8d44\u6e90\u5b89\u5168&#xff0c;\u53ef\u6784\u5efa\u9ad8\u6548\u53ef\u9760\u7684\u6587\u4ef6\u5904\u7406\u6a21\u5757\u3002<\/p>\n<\/p>\n<p>IO\u6d41\u591a\u7ebf\u7a0b\u5b66\u4e60&#xff1a;https:\/\/pan.quark.cn\/s\/5e9f153a70df<\/p>\n<hr \/>\n<p class=\"img-center\"><img loading=\"lazy\" decoding=\"async\" alt=\"\u56fe\u7247\" height=\"1619\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/08\/20250810134417-6898a2316dd71.jpg\" width=\"1080\" \/><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb552\u6b21\uff0c\u70b9\u8d5e11\u6b21\uff0c\u6536\u85cf7\u6b21\u3002\u672c\u6587\u8be6\u7ec6\u4ecb\u7ecd\u4e86Java\u6587\u4ef6\u64cd\u4f5c\u7684\u6838\u5fc3\u6280\u672f\uff0c\u5305\u62ecFile\u7c7b\u548cIO\u6d41\u4f53\u7cfb\u3002File\u7c7b\u7528\u4e8e\u6587\u4ef6\u7cfb\u7edf\u64cd\u4f5c\uff0c\u652f\u6301\u521b\u5efa\u3001\u5220\u9664\u3001\u91cd\u547d\u540d\u7b49\uff0c\u9700\u6ce8\u610f\u5f02\u5e38\u5904\u7406\u3002IO\u6d41\u5206\u4e3a\u5b57\u8282\u6d41\u548c\u5b57\u7b26\u6d41\uff0c\u5206\u522b\u9002\u7528\u4e8e\u4e8c\u8fdb\u5236\u548c\u6587\u672c\u6587\u4ef6\u5904\u7406\u3002\u901a\u8fc7try-with-resources\u8bed\u6cd5\u53ef\u81ea\u52a8\u7ba1\u7406\u8d44\u6e90\uff0c\u907f\u514d\u6cc4\u6f0f\u3002\u6587\u7ae0\u63d0\u4f9b\u4e86\u6587\u4ef6\u8bfb\u5199\u7684\u4ee3\u7801\u793a\u4f8b\uff0c\u5e76\u5f3a\u8c03\u4f7f\u7528\u7f13\u51b2\u6d41\u63d0\u5347\u6027\u80fd\uff08\u5efa\u8bae4KB-8KB\u7f13\u51b2\u533a\uff09\u3002\u6700\u4f73\u5b9e\u8df5\u5305\u62ec\uff1a\u4f18\u5148\u76f8\u5bf9\u8def\u5f84\u3001\u663e\u5f0f\u6307\u5b9a\u5b57\u7b26\u96c6\u7f16\u7801\u3001\u89c4\u8303\u5f02\u5e38\u5904\u7406\u3002\u5408\u7406\u8fd0\u7528\u8fd9\u4e9b\u6280\u672f\u53ef\u6784\u5efa\u9ad8\u6548\u53ef\u9760\u7684\u6587\u4ef6\u5904\u7406\u6a21\u5757\u3002<\/p>\n","protected":false},"author":2,"featured_media":51355,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[99,81,87],"topic":[],"class_list":["post-51356","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-server","tag-java","tag-python","tag-87"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Java\u6587\u4ef6\u64cd\u4f5c\u4e0eIO\u6d41\u6838\u5fc3\u6280\u672f\u89e3\u6790 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.wsisp.com\/helps\/51356.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Java\u6587\u4ef6\u64cd\u4f5c\u4e0eIO\u6d41\u6838\u5fc3\u6280\u672f\u89e3\u6790 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb552\u6b21\uff0c\u70b9\u8d5e11\u6b21\uff0c\u6536\u85cf7\u6b21\u3002\u672c\u6587\u8be6\u7ec6\u4ecb\u7ecd\u4e86Java\u6587\u4ef6\u64cd\u4f5c\u7684\u6838\u5fc3\u6280\u672f\uff0c\u5305\u62ecFile\u7c7b\u548cIO\u6d41\u4f53\u7cfb\u3002File\u7c7b\u7528\u4e8e\u6587\u4ef6\u7cfb\u7edf\u64cd\u4f5c\uff0c\u652f\u6301\u521b\u5efa\u3001\u5220\u9664\u3001\u91cd\u547d\u540d\u7b49\uff0c\u9700\u6ce8\u610f\u5f02\u5e38\u5904\u7406\u3002IO\u6d41\u5206\u4e3a\u5b57\u8282\u6d41\u548c\u5b57\u7b26\u6d41\uff0c\u5206\u522b\u9002\u7528\u4e8e\u4e8c\u8fdb\u5236\u548c\u6587\u672c\u6587\u4ef6\u5904\u7406\u3002\u901a\u8fc7try-with-resources\u8bed\u6cd5\u53ef\u81ea\u52a8\u7ba1\u7406\u8d44\u6e90\uff0c\u907f\u514d\u6cc4\u6f0f\u3002\u6587\u7ae0\u63d0\u4f9b\u4e86\u6587\u4ef6\u8bfb\u5199\u7684\u4ee3\u7801\u793a\u4f8b\uff0c\u5e76\u5f3a\u8c03\u4f7f\u7528\u7f13\u51b2\u6d41\u63d0\u5347\u6027\u80fd\uff08\u5efa\u8bae4KB-8KB\u7f13\u51b2\u533a\uff09\u3002\u6700\u4f73\u5b9e\u8df5\u5305\u62ec\uff1a\u4f18\u5148\u76f8\u5bf9\u8def\u5f84\u3001\u663e\u5f0f\u6307\u5b9a\u5b57\u7b26\u96c6\u7f16\u7801\u3001\u89c4\u8303\u5f02\u5e38\u5904\u7406\u3002\u5408\u7406\u8fd0\u7528\u8fd9\u4e9b\u6280\u672f\u53ef\u6784\u5efa\u9ad8\u6548\u53ef\u9760\u7684\u6587\u4ef6\u5904\u7406\u6a21\u5757\u3002\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/51356.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2025-08-10T13:44:20+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/08\/20250810134417-6898a2316dd71.jpg\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/51356.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/51356.html\",\"name\":\"Java\u6587\u4ef6\u64cd\u4f5c\u4e0eIO\u6d41\u6838\u5fc3\u6280\u672f\u89e3\u6790 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2025-08-10T13:44:20+00:00\",\"dateModified\":\"2025-08-10T13:44:20+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/51356.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/51356.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/51356.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Java\u6587\u4ef6\u64cd\u4f5c\u4e0eIO\u6d41\u6838\u5fc3\u6280\u672f\u89e3\u6790\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\",\"url\":\"https:\/\/www.wsisp.com\/helps\/\",\"name\":\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"description\":\"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"zh-Hans\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"contentUrl\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"caption\":\"admin\"},\"sameAs\":[\"http:\/\/wp.wsisp.com\"],\"url\":\"https:\/\/www.wsisp.com\/helps\/author\/admin\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Java\u6587\u4ef6\u64cd\u4f5c\u4e0eIO\u6d41\u6838\u5fc3\u6280\u672f\u89e3\u6790 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.wsisp.com\/helps\/51356.html","og_locale":"zh_CN","og_type":"article","og_title":"Java\u6587\u4ef6\u64cd\u4f5c\u4e0eIO\u6d41\u6838\u5fc3\u6280\u672f\u89e3\u6790 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb552\u6b21\uff0c\u70b9\u8d5e11\u6b21\uff0c\u6536\u85cf7\u6b21\u3002\u672c\u6587\u8be6\u7ec6\u4ecb\u7ecd\u4e86Java\u6587\u4ef6\u64cd\u4f5c\u7684\u6838\u5fc3\u6280\u672f\uff0c\u5305\u62ecFile\u7c7b\u548cIO\u6d41\u4f53\u7cfb\u3002File\u7c7b\u7528\u4e8e\u6587\u4ef6\u7cfb\u7edf\u64cd\u4f5c\uff0c\u652f\u6301\u521b\u5efa\u3001\u5220\u9664\u3001\u91cd\u547d\u540d\u7b49\uff0c\u9700\u6ce8\u610f\u5f02\u5e38\u5904\u7406\u3002IO\u6d41\u5206\u4e3a\u5b57\u8282\u6d41\u548c\u5b57\u7b26\u6d41\uff0c\u5206\u522b\u9002\u7528\u4e8e\u4e8c\u8fdb\u5236\u548c\u6587\u672c\u6587\u4ef6\u5904\u7406\u3002\u901a\u8fc7try-with-resources\u8bed\u6cd5\u53ef\u81ea\u52a8\u7ba1\u7406\u8d44\u6e90\uff0c\u907f\u514d\u6cc4\u6f0f\u3002\u6587\u7ae0\u63d0\u4f9b\u4e86\u6587\u4ef6\u8bfb\u5199\u7684\u4ee3\u7801\u793a\u4f8b\uff0c\u5e76\u5f3a\u8c03\u4f7f\u7528\u7f13\u51b2\u6d41\u63d0\u5347\u6027\u80fd\uff08\u5efa\u8bae4KB-8KB\u7f13\u51b2\u533a\uff09\u3002\u6700\u4f73\u5b9e\u8df5\u5305\u62ec\uff1a\u4f18\u5148\u76f8\u5bf9\u8def\u5f84\u3001\u663e\u5f0f\u6307\u5b9a\u5b57\u7b26\u96c6\u7f16\u7801\u3001\u89c4\u8303\u5f02\u5e38\u5904\u7406\u3002\u5408\u7406\u8fd0\u7528\u8fd9\u4e9b\u6280\u672f\u53ef\u6784\u5efa\u9ad8\u6548\u53ef\u9760\u7684\u6587\u4ef6\u5904\u7406\u6a21\u5757\u3002","og_url":"https:\/\/www.wsisp.com\/helps\/51356.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2025-08-10T13:44:20+00:00","og_image":[{"url":"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/08\/20250810134417-6898a2316dd71.jpg"}],"author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"1 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/51356.html","url":"https:\/\/www.wsisp.com\/helps\/51356.html","name":"Java\u6587\u4ef6\u64cd\u4f5c\u4e0eIO\u6d41\u6838\u5fc3\u6280\u672f\u89e3\u6790 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2025-08-10T13:44:20+00:00","dateModified":"2025-08-10T13:44:20+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/51356.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/51356.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/51356.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"Java\u6587\u4ef6\u64cd\u4f5c\u4e0eIO\u6d41\u6838\u5fc3\u6280\u672f\u89e3\u6790"}]},{"@type":"WebSite","@id":"https:\/\/www.wsisp.com\/helps\/#website","url":"https:\/\/www.wsisp.com\/helps\/","name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","description":"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"zh-Hans"},{"@type":"Person","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41","name":"admin","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/","url":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","contentUrl":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","caption":"admin"},"sameAs":["http:\/\/wp.wsisp.com"],"url":"https:\/\/www.wsisp.com\/helps\/author\/admin"}]}},"_links":{"self":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/51356","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/comments?post=51356"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/51356\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media\/51355"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=51356"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=51356"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=51356"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=51356"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}