{"id":65871,"date":"2025-05-03T16:16:36","date_gmt":"2025-05-03T08:16:36","guid":{"rendered":"https:\/\/fwq.ai\/blog\/65871\/"},"modified":"2025-05-03T16:16:36","modified_gmt":"2025-05-03T08:16:36","slug":"java%e6%89%93%e5%8d%b0%e6%95%b0%e7%bb%84%e6%80%8e%e4%b9%88%e6%98%af%e4%b9%b1%e7%a0%81-2","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/65871\/","title":{"rendered":"java\u6253\u5370\u6570\u7ec4\u600e\u4e48\u662f\u4e71\u7801"},"content":{"rendered":"<blockquote><p>\n  \u89e3\u51b3 java \u6570\u7ec4\u4e71\u7801\u95ee\u9898\u9700\u8981\uff1a\u627e\u51fa\u7f16\u7801\uff08system.getproperty(&#8220;file.encoding&#8221;))\u8bbe\u7f6e\u6b63\u786e\u7f16\u7801\uff08new outputstreamwriter(system.out, &#8220;utf-8&#8221;), new printstream(osw), system.setout(ps))\u91cd\u65b0\u6253\u5370\u6570\u7ec4\u4ee5\u663e\u793a\u6b63\u786e\u7f16\u7801\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202411\/13\/2024111313335524959.jpg\" class=\"aligncenter\" title=\"java\u6253\u5370\u6570\u7ec4\u600e\u4e48\u662f\u4e71\u7801\u63d2\u56fe\" alt=\"java\u6253\u5370\u6570\u7ec4\u600e\u4e48\u662f\u4e71\u7801\u63d2\u56fe\" \/><\/p>\n<p><strong>Java \u6253\u5370\u6570\u7ec4\u4e71\u7801\u7684\u89e3\u51b3\u65b9\u6cd5<\/strong><\/p>\n<p>\u5f53\u5728 Java \u4e2d\u6253\u5370\u6570\u7ec4\u65f6\u51fa\u73b0\u4e71\u7801\uff0c\u901a\u5e38\u662f\u7531\u4e8e\u7f16\u7801\u95ee\u9898\u9020\u6210\u7684\u3002\u4ee5\u4e0b\u662f\u5982\u4f55\u89e3\u51b3\u6b64\u95ee\u9898\u7684\u6b65\u9aa4\uff1a<\/p>\n<p><strong>\u627e\u51fa\u7f16\u7801<\/strong><\/p>\n<p>\u9996\u5148\uff0c\u786e\u5b9a\u6570\u7ec4\u5143\u7d20\u4f7f\u7528\u7684\u7f16\u7801\u3002\u8fd9\u53ef\u4ee5\u901a\u8fc7\u4f7f\u7528 System.getProperty(&#8220;file.encoding&#8221;) \u83b7\u53d6\u7cfb\u7edf\u9ed8\u8ba4\u7f16\u7801\u6765\u5b8c\u6210\u3002<\/p>\n<p><span>\u7acb\u5373\u5b66\u4e60<\/span>\u201c\u201d\uff1b<\/p>\n<p><strong>\u8bbe\u7f6e\u6b63\u786e\u7684\u7f16\u7801<\/strong><\/p>\n<p>\u4e00\u65e6\u77e5\u9053\u7f16\u7801\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u4ee3\u7801\u8bbe\u7f6e\u6b63\u786e\u7684\u7f16\u7801\uff1a<\/p>\n<pre>OutputStreamWriter osw = new OutputStreamWriter(System.out, \"UTF-8\");\nPrintStream ps = new PrintStream(osw);\nSystem.setOut(ps);<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u91cd\u65b0\u6253\u5370\u6570\u7ec4<\/strong><\/p>\n<p>\u8bbe\u7f6e\u5b8c\u7f16\u7801\u540e\uff0c\u53ef\u4ee5\u91cd\u65b0\u6253\u5370\u6570\u7ec4\uff0c\u5b83\u5c06\u4ee5\u6b63\u786e\u7684\u7f16\u7801\u663e\u793a\u3002<\/p>\n<p><strong>\u793a\u4f8b<\/strong><\/p>\n<p>\u5047\u8bbe\u6709\u4e00\u4e2a\u5305\u542b\u4e2d\u6587\u5b57\u7b26\u7684\u6570\u7ec4\uff1a<\/p>\n<pre>String[] arr = {\"\u4f60\u597d\", \"\u4e16\u754c\"};<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u5982\u679c\u4ee5\u9ed8\u8ba4\u7f16\u7801\u6253\u5370\u6570\u7ec4\uff0c\u5219\u4f1a\u5bfc\u81f4\u4e71\u7801\uff1a<\/p>\n<pre>System.out.println(Arrays.toString(arr)); \/\/ \u4e71\u7801<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u4f7f\u7528\u4ee5\u4e0b\u4ee3\u7801\u8bbe\u7f6e UTF-8 \u7f16\u7801\u540e\uff0c\u6570\u7ec4\u5c06\u6b63\u786e\u6253\u5370\uff1a<\/p>\n<pre>OutputStreamWriter osw = new OutputStreamWriter(System.out, \"UTF-8\");\nPrintStream ps = new PrintStream(osw);\nSystem.setOut(ps);\nSystem.out.println(Arrays.toString(arr)); \/\/ \u6b63\u786e\u6253\u5370<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u4ee5\u4e0a\u5c31\u662fjava\u6253\u5370\u6570\u7ec4\u600e\u4e48\u662f\u4e71\u7801\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8IDCBABY\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u89e3\u51b3 java \u6570\u7ec4\u4e71\u7801\u95ee\u9898\u9700\u8981\uff1a\u627e\u51fa\u7f16\u7801\uff08system.getproperty(&#8220;file.encoding&#8221;))\u8bbe\u7f6e\u6b63\u786e\u7f16\u7801\uff08new outputstreamwriter(system.out, &#8220;utf-8&#8221;), new printstream(osw), system.setout(ps))\u91cd\u65b0\u6253\u5370\u6570\u7ec4\u4ee5\u663e\u793a\u6b63\u786e\u7f16\u7801 Java \u6253\u5370\u6570\u7ec4\u4e71\u7801\u7684\u89e3\u51b3\u65b9\u6cd5 \u5f53\u5728 Java \u4e2d\u6253\u5370\u6570\u7ec4\u65f6\u51fa\u73b0\u4e71\u7801\uff0c\u901a\u5e38\u662f\u7531\u4e8e\u7f16\u7801\u95ee\u9898\u9020\u6210\u7684\u3002\u4ee5\u4e0b\u662f\u5982\u4f55\u89e3\u51b3\u6b64\u95ee\u9898\u7684\u6b65\u9aa4\uff1a \u627e\u51fa\u7f16\u7801 \u9996\u5148\uff0c\u786e\u5b9a\u6570\u7ec4\u5143\u7d20\u4f7f\u7528\u7684\u7f16\u7801\u3002\u8fd9\u53ef\u4ee5\u901a\u8fc7\u4f7f\u7528 System.getProperty(&#8220;file.encoding&#8221;) \u83b7\u53d6\u7cfb\u7edf\u9ed8\u8ba4\u7f16\u7801\u6765\u5b8c\u6210\u3002 \u7acb\u5373\u5b66\u4e60\u201c\u201d\uff1b \u8bbe\u7f6e\u6b63\u786e\u7684\u7f16\u7801 \u4e00\u65e6\u77e5\u9053\u7f16\u7801\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u4ee3\u7801\u8bbe\u7f6e\u6b63\u786e\u7684\u7f16\u7801\uff1a OutputStreamWriter osw = new OutputStreamWriter(System.out, &#8220;UTF-8&#8221;); PrintStream ps = new PrintStream(osw); System.setOut(ps); \u767b\u5f55\u540e\u590d\u5236 \u91cd\u65b0\u6253\u5370\u6570\u7ec4 \u8bbe\u7f6e\u5b8c\u7f16\u7801\u540e\uff0c\u53ef\u4ee5\u91cd\u65b0\u6253\u5370\u6570\u7ec4\uff0c\u5b83\u5c06\u4ee5\u6b63\u786e\u7684\u7f16\u7801\u663e\u793a\u3002 \u793a\u4f8b \u5047\u8bbe\u6709\u4e00\u4e2a\u5305\u542b\u4e2d\u6587\u5b57\u7b26\u7684\u6570\u7ec4\uff1a String[] arr = {&#8220;\u4f60\u597d&#8221;, &#8220;\u4e16\u754c&#8221;}; \u767b\u5f55\u540e\u590d\u5236 \u5982\u679c\u4ee5\u9ed8\u8ba4\u7f16\u7801\u6253\u5370\u6570\u7ec4\uff0c\u5219\u4f1a\u5bfc\u81f4\u4e71\u7801\uff1a System.out.println(Arrays.toString(arr)); \/\/ \u4e71\u7801 \u767b\u5f55\u540e\u590d\u5236 \u4f7f\u7528\u4ee5\u4e0b\u4ee3\u7801\u8bbe\u7f6e UTF-8 \u7f16\u7801\u540e\uff0c\u6570\u7ec4\u5c06\u6b63\u786e\u6253\u5370\uff1a OutputStreamWriter osw = new [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-65871","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/65871","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=65871"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/65871\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=65871"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=65871"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=65871"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}