{"id":100,"date":"2019-07-24T20:26:28","date_gmt":"2019-07-24T12:26:28","guid":{"rendered":"http:\/\/diuut.xyz\/?p=100"},"modified":"2019-07-24T20:26:28","modified_gmt":"2019-07-24T12:26:28","slug":"properties%e6%b7%bb%e5%8a%a0%e6%88%96%e4%bf%ae%e6%94%b9%e5%b1%9e%e6%80%a7%e4%bc%9a%e6%b8%85%e7%a9%ba%e6%96%87%e4%bb%b6","status":"publish","type":"post","link":"https:\/\/diuut.com\/?p=100","title":{"rendered":"Properties\u6dfb\u52a0\u6216\u4fee\u6539\u5c5e\u6027\u4f1a\u6e05\u7a7a\u6587\u4ef6"},"content":{"rendered":"\n<p>\u8fd9\u662f\u4e00\u6bb5\u731c\u6570\u5b57\u7684\u6e38\u620f\u4ee3\u7801\u3002\u540c\u9879\u76ee\u6587\u4ef6\u5939\u4e0b\u6709\u4e2agame.txt\u6587\u4ef6\u5185\u5bb9\u53ea\u6709\u201ccount=3\uff08\u6b21\u6570\uff09\u201d\uff0c\u5728\u5176\u4ed6\u4ee3\u7801\u529f\u80fd\u6d4b\u8bd5\u5168\u90e8\u901a\u8fc7\u7684\u60c5\u51b5\u4e0b\u552f\u72ec\u52a0\u5165\u6570\u636e\u6d41\u4ee5\u540e\u5c31\u5f00\u59cb\u83b7\u53d6\u4e0d\u5230\u503c\u3002<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"> <pre class=\"brush: java; title: ; notranslate\" title=\"\"> \nimport java.io.*;\nimport java.util.Properties;\nimport java.util.Random;\nimport java.util.Scanner;\n\n&lt;em&gt;\/**\n * &lt;\/em&gt;&lt;strong&gt;&lt;em&gt;@Author &lt;\/em&gt;&lt;\/strong&gt;&lt;em&gt;Diuut\n * &lt;\/em&gt;&lt;strong&gt;&lt;em&gt;@Date &lt;\/em&gt;&lt;\/strong&gt;&lt;em&gt;2019\/7\/24  16:23\n *\/\n&lt;\/em&gt;public class GuessGame {\n    public static void main(String[] args) throws IOException {\n        Properties prop = new Properties();\n        BufferedReader bis = new BufferedReader(new FileReader(&quot;Week04\\\\game.txt&quot;));\n        BufferedWriter bos = new BufferedWriter(new FileWriter(&quot;Week04\\\\game.txt&quot;)); \n        prop.load(bis);\n        int count = Integer.&lt;em&gt;parseInt&lt;\/em&gt;(prop.getProperty(&quot;count&quot;));\n        Scanner sc = new Scanner(System.&lt;em&gt;in&lt;\/em&gt;);\n        int choose = 1;\n        while (choose == 1 &amp;amp;&amp;amp; count &amp;gt; 0) {\n            &lt;em&gt;Game&lt;\/em&gt;();\n            count--;\n            String ct = count + &quot;&quot;;\n            prop.setProperty(&quot;count&quot;, ct);\n            prop.store(bos, null);\n            System.&lt;em&gt;out&lt;\/em&gt;.println(&quot;\u662f\u5426\u518d\u73a9\u4e00\u6b21\uff1f\u8f93\u51651\u7ee7\u7eed\uff0c\u8f93\u5165\u5176\u4ed6\u9000\u51fa&quot;);\n            choose = sc.nextInt();\n            if (choose != 1) {\n                bis.close();\n                bos.close();\n                break;\n            }\n        }\n        if (choose == 1 &amp;amp;&amp;amp; count == 0)\n            System.&lt;em&gt;out&lt;\/em&gt;.println(&quot;\u5269\u4f59\u6b21\u6570\u4e3a0\uff0c\u8bf7\u4e0adiuut.xyz\u5145\u503c&quot;);\n        prop.setProperty(&quot;count&quot;, prop.getProperty(&quot;count&quot;));\n        prop.store(bos, null);\n        bis.close();\n        bos.close();\n    }\n    public static void Game() {\n        Random rd = new Random();\n        int num = rd.nextInt(100) + 1;\n        Scanner sc = new Scanner(System.&lt;em&gt;in&lt;\/em&gt;);\n        System.&lt;em&gt;out&lt;\/em&gt;.println(&quot;\u8bf7\u8f93\u51651-100\u4e4b\u95f4\u7684\u4e00\u4e2a\u6574\u6570:&quot;);\n        int inNum = sc.nextInt();\n        while (num != inNum) {\n            if (inNum &amp;gt; 0 &amp;amp;&amp;amp; inNum &amp;lt; num) {\n                System.&lt;em&gt;out&lt;\/em&gt;.println(&quot;\u60a8\u8f93\u5165\u7684\u6570\u5b57\u5c0f\u4e86\uff0c\u8bf7\u91cd\u65b0\u8f93\u5165\uff1a&quot;);\n                inNum = sc.nextInt();\n            } else if (inNum &amp;lt; 101 &amp;amp;&amp;amp; inNum &amp;gt; num) {\n                System.&lt;em&gt;out&lt;\/em&gt;.println(&quot;\u60a8\u8f93\u5165\u7684\u6570\u5b57\u5927\u4e86\uff0c\u8bf7\u91cd\u65b0\u8f93\u5165\uff1a&quot;);\n                inNum = sc.nextInt();\n            } else {\n                System.&lt;em&gt;out&lt;\/em&gt;.println(&quot;\u60a8\u8f93\u5165\u7684\u6570\u5b57\u4e0d\u5728100\u8303\u56f4\u4e4b\u5185\uff0c\u8bf7\u91cd\u65b0\u8f93\u5165:&quot;);\n                inNum = sc.nextInt();\n            }\n        }\n        System.&lt;em&gt;out&lt;\/em&gt;.println(&quot;\u606d\u559c\u60a8\u731c\u5bf9\u4e86\uff0c\u6570\u5b57\u4e3a&quot; + num);\n    }\n}\n <\/pre>  <\/pre>\n\n\n\n<p>\u539f\u56e0\u7ed3\u679c\u662f\u56e0\u4e3a \u521b\u5efaBufferedWriter\u5bf9\u8c61\u65f6\u76f4\u63a5\u628a\u6587\u4ef6\u6e05\u7a7a\u91cd\u7f6e\u4e86\uff0c\u5bfc\u81f4\u540e\u9762properties\u8bfb\u4e0d\u5230\u6570\u636e\uff0c\u8fd9\u91cc\u4e86\u53ea\u9700\u8981\u628aBufferedWriter\u5bf9\u8c61\u653e\u5230load\u65b9\u6cd5\u8bfb\u53d6\u6570\u636e\u4e4b\u540e\u518d\u521b\u5efa\u5c31\u53ef\u4ee5\u6b63\u5e38\u4f7f\u7528\u4e86\u3002<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"> <pre class=\"brush: java; title: ; notranslate\" title=\"\"> \nBufferedReader bis = new BufferedReader(new FileReader(&quot;Week04\\\\game.txt&quot;));\nprop.load(bis);\nBufferedWriter bos = new BufferedWriter(new FileWriter(&quot;Week04\\\\game.txt&quot;));\n <\/pre>  <\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u8fd9\u662f\u4e00\u6bb5\u731c\u6570\u5b57\u7684\u6e38\u620f\u4ee3\u7801\u3002\u540c\u9879\u76ee\u6587\u4ef6\u5939\u4e0b\u6709\u4e2agame.txt\u6587\u4ef6\u5185\u5bb9\u53ea\u6709\u201ccount=3\uff08\u6b21\u6570\uff09\u201d\uff0c\u5728\u5176\u4ed6\u4ee3\u7801<span class=\"more-button\"><a href=\"https:\/\/diuut.com\/?p=100\" class=\"more-link\">view all . . .<span class=\"screen-reader-text\">Properties\u6dfb\u52a0\u6216\u4fee\u6539\u5c5e\u6027\u4f1a\u6e05\u7a7a\u6587\u4ef6<\/span><\/a><\/span><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[2],"tags":[],"_links":{"self":[{"href":"https:\/\/diuut.com\/index.php?rest_route=\/wp\/v2\/posts\/100"}],"collection":[{"href":"https:\/\/diuut.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/diuut.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/diuut.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/diuut.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=100"}],"version-history":[{"count":0,"href":"https:\/\/diuut.com\/index.php?rest_route=\/wp\/v2\/posts\/100\/revisions"}],"wp:attachment":[{"href":"https:\/\/diuut.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=100"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/diuut.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=100"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/diuut.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=100"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}