{"id":1334,"date":"2022-02-27T14:46:49","date_gmt":"2022-02-27T06:46:49","guid":{"rendered":"http:\/\/www.zyhcoding.club\/?p=1334"},"modified":"2022-02-27T20:37:02","modified_gmt":"2022-02-27T12:37:02","slug":"java%e5%9f%ba%e6%9c%aci-o","status":"publish","type":"post","link":"http:\/\/www.zyhcoding.club\/index.php\/2022\/02\/27\/java%e5%9f%ba%e6%9c%aci-o\/","title":{"rendered":"JAVA\u57fa\u672cI\/O"},"content":{"rendered":"<h5>I\/O\u6d41<\/h5>\n<p>\u4e00\u4e2aI\/O\u6d41\u8868\u793a\u8f93\u5165\u6e90\u6216\u8005\u8f93\u51fa\u76ee\u7684\u5730\u3002\u6d41\u53ef\u4ee5\u8868\u793a\u5f88\u591a\u4e0d\u540c\u7c7b\u578b\u7684\u6e90\u548c\u76ee\u7684\u5730\uff0c\u5305\u62ec\u78c1\u76d8\u6587\u4ef6\u3001\u8bbe\u5907\u3001\u5176\u4ed6\u7a0b\u5e8f\u548c\u5b58\u50a8\u5668\u9635\u5217\u3002\u4e00\u4e2a\u6d41\u53ef\u4ee5\u7406\u89e3\u4e3a\u4e00\u4e2a\u6570\u636e\u7684\u5e8f\u5217\u3002<br \/>\n<code>Java.io <\/code>\u5305\u51e0\u4e4e\u5305\u542b\u4e86\u6240\u6709\u64cd\u4f5c\u8f93\u5165\u3001\u8f93\u51fa\u9700\u8981\u7684\u7c7b\u3002<\/p>\n<h5>\u6807\u51c6\u6d41<\/h5>\n<p>Java\u5e73\u53f0\u652f\u6301\u4e09\u79cd\u6807\u51c6\u6d41\uff1a\u6807\u51c6\u8f93\u5165<code>System.in<\/code>\uff0c\u6807\u51c6\u8f93\u51fa<code>System.out<\/code>\uff0c\u6807\u51c6\u9519\u8bef<code>System.err<\/code>\u3002<\/p>\n<h5>\u5b57\u8282\u6d41\u548c\u5b57\u7b26\u6d41<\/h5>\n<p><img src=\"http:\/\/www.zyhcoding.club:80\/wp-content\/uploads\/2022\/02\/\u5b57\u8282\u6d41\u548c\u5b57\u7b26\u6d41.png\" alt=\"\" \/><\/p>\n<p>\u5b57\u8282\u6d41\u662f\u6700\u57fa\u672c\u7c7b\u578b\u7684\u6d41\uff0c\u6240\u6709\u5b57\u8282\u6d41\u7c7b\u90fd\u662f\u4ece<code>InputStream<\/code>\u548c<code>OutputStream<\/code>\u7ee7\u627f\u6765\u7684\u3002\u5b57\u7b26\u6d41\u80fd\u591f\u81ea\u52a8\u9002\u5e94\u672c\u5730\u5b57\u7b26\u96c6\uff0c\u7528\u6d41\u7c7b\u5b9e\u73b0\u7684\u8f93\u5165\u8f93\u51fa\u80fd\u81ea\u52a8\u5730\u4e0e\u672c\u5730\u5b57\u7b26\u96c6\u4e92\u76f8\u8f6c\u6362\u3002\u6240\u4ee5\u5b57\u7b26\u6d41\u7c7b\u90fd\u662f\u4ece<code>Reader<\/code>\u548c<code>Writer<\/code>\u7ee7\u627f\u6765\u7684\u3002<\/p>\n<p>\u5bf9\u4e8e<code>\u65e0\u7f13\u51b2I\/O<\/code>\uff0c\u6bcf\u4e2a\u8bfb\u53d6\u6216\u5b58\u5165\u8bf7\u6c42\u90fd\u662f\u5e95\u5c42\u64cd\u4f5c\u7cfb\u7edf\u76f4\u63a5\u5904\u7406\u7684\uff0c\u6bcf\u4e2a\u8fd9\u6837\u7684\u8bf7\u6c42\u5e38\u5e38\u4f1a\u89e6\u53d1\u78c1\u76d8\u5b58\u53d6\u3001\u7f51\u7edc\u6d3b\u52a8\u6216\u5176\u4ed6\u76f8\u5bf9\u6602\u8d35\u7684\u64cd\u4f5c\uff0c\u6240\u4ee5\u5bfc\u81f4\u7a0b\u5e8f\u7684\u6548\u7387\u5f88\u4f4e\u3002Java\u5e73\u53f0\u5b9e\u73b0\u4e86<code>\u7f13\u51b2I\/O\u6d41<\/code>\u3002\u7f13\u51b2\u8f93\u5165\u6d41\u4ece\u5185\u5b58\u7f13\u51b2\u533a\u8bfb\u53d6\u6570\u636e\uff0c\u7f13\u51b2\u533a\u7a7a\u65f6\u624d\u8c03\u7528\u672c\u5730\u8f93\u5165API\uff1b\u88ab\u7f13\u51b2\u7684\u8f93\u51fa\u6d41\u628a\u6570\u636e\u5199\u5165\u7f13\u51b2\u533a\uff0c\u7f13\u51b2\u533a\u6ee1\u662f\u624d\u8c03\u7528\u672c\u5730\u8f93\u51faAPI\u3002<\/p>\n<p>\u4e0b\u4f8b\u6f14\u793a\u4ece\u6587\u4ef6\u8bfb\u53d6\u5e76\u8f93\u51fa\u5230\u63a7\u5236\u53f0\uff1a<\/p>\n<pre><code class=\"language-java\">import java.io.*;\nimport java.util.Scanner;\npublic class ScanXan{\n    public static void main(String[] args) throws IOException{\n        Scanner s = null;\n\n        try {\n            s = new Scanner(new BufferedReader(new FileReader(&quot;xanadu.txt&quot;)));  \/\/\u8bfb\u53d6\u6587\u4ef6\u5e76\u7ed1\u5b9a\u5230\u7f13\u51b2\u6d41\uff0c\u518d\u7ed1\u5b9a\u5230Scanner\u626b\u63cf\u5668\n\n            while (s.hasNext()) {\n                System.out.println(s.next());\n            }\n        } finally {\n            if (s!=null) {\n                s.close();\n            }\n        }\n    }\n}<\/code><\/pre>\n<h5>format\u65b9\u6cd5<\/h5>\n<p>format\u65b9\u6cd5\u53ef\u4ee5\u6839\u636e\u683c\u5f0f\u5316\u5b57\u7b26\u683c\u5f0f\u5316\u591a\u4e2a\u53c2\u6570\u3002\u6240\u6709\u7684\u683c\u5f0f\u5316\u6807\u8bc6\u7b26\u90fd\u662f\u4ee5\u767e\u5206\u53f7<code>%<\/code>\u5f00\u5934\u3002<\/p>\n<pre><code class=\"language-java\">%% \u8f93\u51fa%\n%n \u8f93\u51fa\u5e73\u53f0\u7279\u5b9a\u7684\u884c\u7ec8\u6b62\u7b26\u3002\\n\u4e5f\u53ef\u4ee5\u4f46\u5c3d\u91cf\u4e0d\u8981\u7528\u8fd9\u4e2a\n%d \u8868\u793a\u628a\u6574\u578b\u503c\u683c\u5f0f\u5316\u4e3a\u5341\u8fdb\u5236\u503c\n%f \u628a\u6d6e\u70b9\u503c\u683c\u5f0f\u5316\u4e3a\u5341\u8fdb\u5236\u503c\n%x \u628a\u6574\u6570\u683c\u5f0f\u5316\u4e3a\u5341\u516d\u8fdb\u5236\n%s \u628a\u4efb\u610f\u503c\u683c\u5f0f\u5316\u4e3a\u5b57\u7b26\u4e32\n\nSystem.out.format(&quot;%f, %1$+020.10f %n&quot;, Math.PI);\n\/\/\u6807\u5fd7+\u8868\u793a\u8fd9\u4e2a\u6570\u5e94\u8be5\u7528\u7b26\u53f7\u683c\u5f0f\u5316\uff1b0\u8868\u793a\u8865\u4f4d\u5b57\u7b26\uff1b20\u8868\u793a\u5bbd\u5ea6\uff1b10\u8868\u793a\u7cbe\u5ea6\n\/\/1$\u548c&lt;\u90fd\u53ef\u4ee5\u8868\u793a\u53c2\u6570\u7d22\u5f15\u3002<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>I\/O\u6d41 \u4e00\u4e2aI\/O\u6d41\u8868\u793a\u8f93\u5165\u6e90\u6216\u8005\u8f93\u51fa\u76ee\u7684\u5730\u3002\u6d41\u53ef\u4ee5\u8868\u793a\u5f88\u591a\u4e0d\u540c\u7c7b\u578b\u7684\u6e90\u548c\u76ee\u7684\u5730\uff0c\u5305\u62ec\u78c1\u76d8\u6587\u4ef6\u3001\u8bbe [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[67,75],"tags":[],"_links":{"self":[{"href":"http:\/\/www.zyhcoding.club\/index.php\/wp-json\/wp\/v2\/posts\/1334"}],"collection":[{"href":"http:\/\/www.zyhcoding.club\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.zyhcoding.club\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.zyhcoding.club\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.zyhcoding.club\/index.php\/wp-json\/wp\/v2\/comments?post=1334"}],"version-history":[{"count":5,"href":"http:\/\/www.zyhcoding.club\/index.php\/wp-json\/wp\/v2\/posts\/1334\/revisions"}],"predecessor-version":[{"id":1340,"href":"http:\/\/www.zyhcoding.club\/index.php\/wp-json\/wp\/v2\/posts\/1334\/revisions\/1340"}],"wp:attachment":[{"href":"http:\/\/www.zyhcoding.club\/index.php\/wp-json\/wp\/v2\/media?parent=1334"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.zyhcoding.club\/index.php\/wp-json\/wp\/v2\/categories?post=1334"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.zyhcoding.club\/index.php\/wp-json\/wp\/v2\/tags?post=1334"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}