{"id":417,"date":"2013-02-13T11:29:42","date_gmt":"2013-02-13T11:29:42","guid":{"rendered":"http:\/\/lg.yusemo.com\/?p=417"},"modified":"2016-08-25T09:47:44","modified_gmt":"2016-08-25T09:47:44","slug":"java-character-encoding-series-unicode-iso-8859-1-gbk-utf-8-encoding-and-conversion","status":"publish","type":"post","link":"https:\/\/lg.yusemo.com\/?p=417","title":{"rendered":"JAVA\u5b57\u7b26\u7f16\u7801\u7cfb\u5217\u4e4bUnicode,ISO-8859-1,GBK,UTF-8\u7f16\u7801\u53ca\u76f8\u4e92\u8f6c\u6362"},"content":{"rendered":"<p>\u4e3a\u4e86\u6784\u6210\u4e00\u4e2a\u5b8c\u6574\u7684\u5bf9\u6587\u5b57\u7f16\u7801\u7684\u8ba4\u8bc6\u548c\u6df1\u5165\u628a\u63e1\uff0c\u4ee5\u4fbf\u5904\u7406\u5728Java\u5f00\u53d1\u8fc7\u7a0b\u4e2d\u9047\u5230\u7684\u5404\u79cd\u95ee\u9898\uff0c\u7279\u522b\u662f\u4e71\u7801\u95ee\u9898\uff0c\u6211\u89c9\u5f97\u7ec4\u6210\u4e00\u4e2a\u7cfb\u5217\u6765\u63cf\u8ff0\u548c\u5206\u6790\u66f4\u597d\u4e00\u4e9b\uff0c\u5305\u62ec\u4e09\u7bc7\u6587\u7ae0\uff1a<\/p>\n<p>\u7b2c\u4e00\u7bc7\uff1aJAVA\u5b57\u7b26\u7f16\u7801\u7cfb\u5217\u4e00\uff1a<a title=\"JAVA\u5b57\u7b26\u7f16\u7801\u7cfb\u5217\u4e4bUnicode,GBK,GB2312,UTF-8\u6982\u5ff5\u57fa\u7840\" href=\"http:\/\/lg.yusemo.com\/bian-ma-xi-lie-unicode-gbk-gb2312-utf-8\">Unicode,GBK,GB2312,UTF-8\u6982\u5ff5\u57fa\u7840<\/a><\/p>\n<p>\u7b2c\u4e8c\u7bc7\uff1aJAVA\u5b57\u7b26\u7f16\u7801\u7cfb\u5217\u4e8c\uff1a<a title=\"Unicode,ISO-8859,GBK,UTF-8\u7f16\u7801\u53ca\u76f8\u4e92\u8f6c\u6362\" href=\"http:\/\/lg.yusemo.com\/java-character-encoding-series-unicode-iso8859-1-gbk-utf8-conversion\">Unicode,ISO-8859,GBK,UTF-8\u7f16\u7801\u53ca\u76f8\u4e92\u8f6c\u6362<\/a><\/p>\n<p>\u7b2c\u4e09\u7bc7\uff1aJAVA\u5b57\u7b26\u7f16\u7801\u7cfb\u5217\u4e09\uff1aJava\u5e94\u7528\u4e2d\u7684\u7f16\u7801\u95ee\u9898<\/p>\n<h1><span style=\"font-size: 13px;\">\uff11\u3001\u51fd\u6570\u4ecb\u7ecd<\/span><\/h1>\n<p>\u5728Java\u4e2d\uff0c\u5b57\u7b26\u4e32\u7528\u7edf\u4e00\u7684Unicode\u7f16\u7801\uff0c\u6bcf\u4e2a\u5b57\u7b26\u5360\u7528\u4e24\u4e2a\u5b57\u8282\uff0c\u4e0e\u7f16\u7801\u6709\u5173\u7684\u4e24\u4e2a\u4e3b\u8981\u51fd\u6570\u4e3a\uff1a<\/p>\n<p>\uff11\uff09\u5c06\u5b57\u7b26\u4e32\u7528\u6307\u5b9a\u7684\u7f16\u7801\u96c6\u5408\u89e3\u6790\u6210\u5b57\u8282\u6570\u7ec4\uff0c\u5b8c\u6210Unicode\uff0d\u3009charsetName\u8f6c\u6362<\/p>\n<p>public byte[] getBytes(String charsetName) throws UnsupportedEncodingException<\/p>\n<p>\uff12\uff09\u5c06\u5b57\u8282\u6570\u7ec4\u4ee5\u6307\u5b9a\u7684\u7f16\u7801\u96c6\u5408\u6784\u9020\u6210\u5b57\u7b26\u4e32\uff0c\u5b8c\u6210charsetName\uff0d\u3009Unicode\u8f6c\u6362<\/p>\n<p>public String(byte[] bytes, String charsetName) throws UnsupportedEncodingException<\/p>\n<p>\uff12\u3001Unicode\u4e0e\u5404\u7f16\u7801\u4e4b\u95f4\u7684\u76f4\u63a5\u8f6c\u6362<\/p>\n<p>\u4e0b\u9762\u4ee5\u5bf9\u4e2d\u6587\u5b57\u7b26\u4e32\uff02\uff41\u4e2d\u6587\uff02\u7684\u7f16\u7801\u8f6c\u6362\u4e3a\u4f8b\uff0c\u6765\u4e86\u89e3\u5404\u79cd\u7f16\u7801\u4e4b\u95f4\u7684\u8f6c\u6362<\/p>\n<p>\uff11\uff09Unicode\u548cGBK<\/p>\n<p>\u6d4b\u8bd5\u7ed3\u679c\u5982\u4e0b\uff0c\u6bcf\u4e2a\u6c49\u5b57\u8f6c\u6362\u4e3a\u4e24\u4e2a\u5b57\u8282\uff0c\u4e14\u662f\u53ef\u9006\u7684\uff0c\u5373\u901a\u8fc7\u5b57\u8282\u53ef\u4ee5\u8f6c\u6362\u56de\u5b57\u7b26\u4e32<\/p>\n<p>String\uff0dGBK\u3009ByteArray\uff1a\\u0061\\u4E2D\\u6587\uff08a\u4e2d\u6587\uff09\uff0d\u30090x61 0xD6 0xD0 0xCE 0xC4<\/p>\n<p>ByteArray\uff0dGBK\u3009String\uff1a0x61 0xD6 0xD0 0xCE 0xC4\uff0d\u3009\\u0061\\u4E2D\\u6587\uff08a\u4e2d\u6587\uff09<\/p>\n<p>\uff12\uff09Unicode\u548cUTF-8<\/p>\n<p>\u6d4b\u8bd5\u7ed3\u679c\u5982\u4e0b\uff0c\u6bcf\u4e2a\u6c49\u5b57\u8f6c\u6362\u4e3a\u4e09\u4e2a\u5b57\u8282\uff0c\u4e14\u662f\u53ef\u9006\u7684\uff0c\u5373\u901a\u8fc7\u5b57\u8282\u53ef\u4ee5\u8f6c\u6362\u56de\u5b57\u7b26\u4e32<\/p>\n<p>String\uff0dUTF-8\u3009ByteArray\uff1a\\u0061\\u4E2D\\u6587\uff08a\u4e2d\u6587\uff09\uff0d\u30090x61 0xE4 0xB8 0xAD 0xE6%0x96 0x87<\/p>\n<p>ByteArray\uff0dUTF-8\u3009String\uff1a0x61 0xE4 0xB8 0xAD 0xE6%0x96 0x87\uff0d\u3009\\u0061\\u4E2D\\u6587\uff08a\u4e2d\u6587\uff09<\/p>\n<p>\uff13\uff09Unicode\u548cISO-8859-1<\/p>\n<p>\u6d4b\u8bd5\u7ed3\u679c\u5982\u4e0b\uff0c\u5f53\u5b58\u5728\u6c49\u5b57\u65f6\u8f6c\u6362\u5931\u8d25\uff0c\u975e\u53ef\u9006\uff0c\u5373\u901a\u8fc7\u5b57\u8282\u4e0d\u80fd\u518d\u8f6c\u6362\u56de\u5b57\u7b26\u4e32<\/p>\n<p>String\uff0dISO-8859-1\u3009ByteArray\uff1a\\u0061\\u4E2D\\u6587\uff08a\u4e2d\u6587\uff09\uff0d\u30090x61 0x3F0x3F<\/p>\n<p>ByteArray\uff0dISO-8859-1\u3009String\uff1a0x61 0x3F0x3F\uff0d\u3009\\u0061\\u003F\\u003F\uff08a??\uff09<\/p>\n<p>\uff13\u3001Unicode\u4e0e\u5404\u7f16\u7801\u4e4b\u95f4\u7684\u4ea4\u53c9\u8f6c\u6362<\/p>\n<p>\u5728\u4e0a\u9762\u76f4\u63a5\u8f6c\u6362\u4e2d\uff0c\u7531\u5b57\u7b26\u4e32\uff08Unicode\uff09\u751f\u6210\u7684\u5b57\u8282\u6570\u7ec4\uff0c\u5728\u6784\u9020\u56de\u5b57\u7b26\u4e32\u65f6\uff0c\u4f7f\u7528\u7684\u662f\u6b63\u786e\u7684\u7f16\u7801\u96c6\u5408\uff0c\u5982\u679c\u4f7f\u7528\u7684\u4e0d\u662f\u6b63\u786e\u7684\u7f16\u7801\u96c6\u5408\u4f1a\u600e\u6837\u5462\uff1f\u4f1a\u6b63\u786e\u6784\u9020\u5417\uff1f\u5982\u679c\u4e0d\u80fd\u6b63\u786e\u6784\u9020\u80fd\u6709\u529e\u6cd5\u6062\u590d\u5417\uff1f\u4f1a\u4fe1\u606f\u4e22\u5931\u5417\uff1f<\/p>\n<p>\u4e0b\u9762\u6211\u4eec\u5c31\u6765\u770b\u770b\u8fd9\u79cd\u60c5\u51b5\uff0c\u8fd9\u90e8\u5206\u53ef\u4ee5\u8bf4\u660e\u5728\u67d0\u4e9b\u60c5\u51b5\u4e0b\u867d\u7136\u6211\u4eec\u6700\u7ec8\u6b63\u786e\u663e\u793a\u4e86\u7ed3\u679c\uff0c\u4f46\u5176\u95f4\u4ecd\u7136\u8fdb\u884c\u4e86\u4e0d\u6b63\u786e\u7684\u8f6c\u6362\u3002<\/p>\n<p>\uff11\uff09\u80fd\u591f\u6b63\u786e\u663e\u793a\u7684\u4e2d\u95f4\u4e0d\u6b63\u786e\u8f6c\u6362<\/p>\n<p>\u6211\u4eec\u77e5\u9053String\uff0dGBK\u3009ByteArray\uff0dGBK\u3009String\u662f\u6b63\u786e\u7684\uff0c\u4f46\u5982\u679c\u6211\u4eec\u91c7\u7528String\uff0dGBK\u3009ByteArray\uff0dISO-8859-1\u3009String\u5462\uff1f\u901a\u8fc7\u6d4b\u8bd5\u7ed3\u679c\u5982\u4e0b\uff1a<\/p>\n<p>String\uff0dGBK\u3009ByteArray\uff0dISO-8859-1\u3009String\uff1a\\u0061\\u4E2D\\u6587\uff08a\u4e2d\u6587\uff09\uff0d\u30090x61 0xD6 0xD0 0xCE 0xC4\uff0d\u3009\\u0061\\u00D6\\u00D0\\u00CE\\u00C4\uff08a????\uff09<\/p>\n<p>\u8fd9\u65f6\u6211\u4eec\u5f97\u5230\u7684\u5b57\u7b26\u4e32\u4e3a\uff1f\u4e71\u7801\u201ca????\u201d\uff0c\u4f46\u662f\u901a\u8fc7\u7ee7\u7eed\u8f6c\u6362\u6211\u4eec\u4ecd\u7136\u53ef\u4ee5\u590d\u539f\u56de\u6b63\u786e\u7684\u5b57\u7b26\u4e32\u201ca\u4e2d\u6587\u201d\uff0c\u8fc7\u7a0b\u5982\u4e0b\uff1a<\/p>\n<p>String\uff0dGBK\u3009ByteArray\uff0dISO-8859-1\u3009String\uff0dISO-8859-1\u3009ByteArray\uff0dGBK\u3009String<\/p>\n<p>\u5bf9\u5e94\uff1a\\u0061\\u4E2D\\u6587\uff08a\u4e2d\u6587\uff09\uff0d\u30090x61 0xD6 0xD0 0xCE 0xC4\uff0d\u3009\\u0061\\u00D6\\u00D0\\u00CE\\u00C4\uff08a????\uff09\uff0d\u30090x61 0xD6 0xD0 0xCE 0xC4\uff0d\u3009\\u0061\\u4E2D\\u6587\uff08a\u4e2d\u6587\uff09<\/p>\n<p>\u4e5f\u5c31\u662f\u6211\u4eec\u5728\u9996\u6b21\u6784\u9020\u5b57\u7b26\u4e32\u65f6\uff0c\u6211\u4eec\u7528\u4e86\u9519\u8bef\u7684\u7f16\u7801\u96c6\u5408\u5f97\u5230\u4e86\u9519\u8bef\u7684\u4e71\u7801\uff0c\u4f46\u662f\u6211\u4eec\u901a\u8fc7\u9519\u4e0a\u52a0\u9519\uff0c\u518d\u7528\u9519\u8bef\u7684\u7f16\u7801\u96c6\u5408\u83b7\u53d6\u5b57\u8282\u6570\u7ec4\uff0c\u7136\u540e\u518d\u7528\u6b63\u786e\u7684\u7f16\u7801\u96c6\u5408\u6784\u9020\uff0c\u5c31\u53c8\u6062\u590d\u4e86\u6b63\u786e\u7684\u5b57\u7b26\u4e32\u3002\u8fd9\u65f6\u5c31\u5c5e\u4e8e\u662f\u201c\u80fd\u591f\u6b63\u786e\u663e\u793a\u7684\u4e2d\u95f4\u4e0d\u6b63\u786e\u8f6c\u6362\u201d\u3002\u5728Jsp\u9875\u9762\u63d0\u4ea4\u6570\u636e\u5904\u7406\u65f6\u5e38\u5e38\u53d1\u751f\u8fd9\u79cd\u60c5\u51b5\u3002<\/p>\n<p>\u6b64\u5916\u80fd\u591f\u6b63\u786e\u663e\u793a\u7684\u4e2d\u95f4\u4e0d\u6b63\u786e\u8f6c\u6362\u8fd8\u6709\uff1a<\/p>\n<p>String\uff0dUTF-8\u3009ByteArray\uff0dISO-8859-1\u3009String\uff0dISO-8859-1\u3009ByteArray\uff0dUTF-8\u3009String<\/p>\n<p>\u548c<\/p>\n<p>String\uff0dUTF-8\u3009ByteArray\uff0dGBK\u3009String\uff0dGBK\u3009ByteArray\uff0dUTF-8\u3009String<\/p>\n<p>\u5bf9\u5e94\uff1a\\u0061\\u4E2D\\u6587\uff08a\u4e2d\u6587\uff09\uff0d\u30090x61 0xE4 0xB8 0xAD 0xE6%0x96 0x87\uff0d\u3009\\u0061\\u6D93\\uE15F\\u6783\uff08a\u6d93\u6783\uff09\uff0d\u30090x61 0xE4 0xB8 0xAD 0xE6%0x96 0x87\uff0d\u3009\\u0061\\u4E2D\\u6587\uff08a\u4e2d\u6587\uff09<\/p>\n<p>\uff14\u3001\u7f16\u7801\u8fc7\u7a0b\u4e2d\u9519\u8bef\u8bca\u65ad\u53c2\u8003<\/p>\n<p>\uff11\uff09\u4e00\u4e2a\u6c49\u5b57\u5bf9\u5e94\u4e00\u4e2a\u95ee\u53f7<\/p>\n<p>\u5728\u901a\u8fc7ISO-8859-1\u4ece\u5b57\u7b26\u4e32\u83b7\u53d6\u5b57\u8282\u6570\u7ec4\u65f6\uff0c\u7531\u4e8e\u4e00\u4e2aUnicode\u8f6c\u6362\u6210\u4e00\u4e2abyte\uff0c\u5f53\u9047\u5230\u4e0d\u8ba4\u8bc6\u7684Unicode\u65f6\uff0c\u8f6c\u6362\u4e3a0x3F\uff0c\u8fd9\u6837\u65e0\u8bba\u7528\u54ea\u79cd\u7f16\u7801\u6784\u9020\u65f6\u90fd\u4f1a\u4ea7\u751f\u4e00\u4e2a\uff1f\u4e71\u7801\u3002<\/p>\n<p>\uff12\uff09\u4e00\u4e2a\u6c49\u5b57\u5bf9\u5e94\u4e24\u4e2a\u95ee\u53f7<\/p>\n<p>\u5728\u901a\u8fc7GBK\u4ece\u5b57\u7b26\u4e32\u83b7\u53d6\u5b57\u8282\u6570\u7ec4\u65f6\uff0c\u7531\u4e8e\u4e00\u4e2aUnicode\u8f6c\u6362\u6210\u4e24\u4e2abyte\uff0c\u5982\u679c\u6b64\u65f6\u7528ISO-8859-1\u6216\u7528UTF-8\u6784\u9020\u5b57\u7b26\u4e32\u5c31\u4f1a\u51fa\u73b0\u4e24\u4e2a\u95ee\u53f7\u3002<\/p>\n<p>\u82e5\u662f\u901a\u8fc7ISO-8859-1\u6784\u9020\u53ef\u4ee5\u518d\u901a\u8fc7\u4e0a\u9762\u6240\u8bf4\u7684\u9519\u4e0a\u52a0\u9519\u6062\u590d\uff08\u5373\u518d\u901a\u8fc7\u4eceISO-8859-1\u89e3\u6790\uff0c\u7528GBK\u6784\u9020\uff09\uff1b<\/p>\n<p>\u82e5\u662f\u901a\u8fc7UTF-8\u6784\u9020\u5219\u4f1a\u4ea7\u751fUnicode\u5b57\u7b26\uff02\\uFFFD\uff02\uff0c\u4e0d\u80fd\u6062\u590d\uff0c\u82e5\u518d\u901a\u8fc7String\uff0dUTF-8\u3009ByteArray\uff0dGBK\u3009String\uff0c\u5219\u4f1a\u51fa\u73b0\u6742\u7801\uff0c\u5982a\u951f\u65a4\u62f7\u951f\u65a4\u62f7<\/p>\n<p>\uff13\uff09\u4e00\u4e2a\u6c49\u5b57\u5bf9\u5e94\u4e09\u4e2a\u95ee\u53f7<\/p>\n<p>\u5728\u901a\u8fc7UTF-8\u4ece\u5b57\u7b26\u4e32\u83b7\u53d6\u5b57\u8282\u6570\u7ec4\u65f6\uff0c\u7531\u4e8e\u4e00\u4e2aUnicode\u8f6c\u6362\u6210\u4e09\u4e2abyte\uff0c\u5982\u679c\u6b64\u65f6\u7528ISO-8859-1\u6784\u9020\u5b57\u7b26\u4e32\u5c31\u4f1a\u51fa\u73b0\u4e09\u4e2a\u95ee\u53f7\uff1b\u7528GBK\u6784\u9020\u5b57\u7b26\u4e32\u5c31\u4f1a\u51fa\u73b0\u6742\u7801\uff0c\u5982a\u6d93\ue15f\u6783\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4e3a\u4e86\u6784\u6210\u4e00\u4e2a\u5b8c\u6574\u7684\u5bf9\u6587\u5b57\u7f16\u7801\u7684\u8ba4\u8bc6\u548c\u6df1\u5165\u628a\u63e1\uff0c\u4ee5\u4fbf\u5904\u7406\u5728Java\u5f00\u53d1\u8fc7\u7a0b\u4e2d\u9047\u5230\u7684\u5404\u79cd\u95ee\u9898\uff0c\u7279\u522b\u662f\u4e71\u7801\u95ee\u9898\uff0c\u6211\u89c9\u5f97\u7ec4\u6210\u4e00\u4e2a\u7cfb\u5217\u6765\u63cf\u8ff0\u548c\u5206\u6790\u66f4\u597d\u4e00\u4e9b\uff0c\u5305\u62ec\u4e09\u7bc7\u6587\u7ae0\uff1a \u7b2c\u4e00\u7bc7\uff1aJAVA\u5b57\u7b26\u7f16\u7801\u7cfb\u5217\u4e00\uff1aUnicode,GBK,GB2312,UTF-8\u6982\u5ff5\u57fa\u7840 \u7b2c\u4e8c\u7bc7\uff1aJAVA\u5b57\u7b26\u7f16\u7801\u7cfb\u5217\u4e8c\uff1aUnicode,&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[22],"tags":[3],"_links":{"self":[{"href":"https:\/\/lg.yusemo.com\/index.php?rest_route=\/wp\/v2\/posts\/417"}],"collection":[{"href":"https:\/\/lg.yusemo.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lg.yusemo.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lg.yusemo.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/lg.yusemo.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=417"}],"version-history":[{"count":4,"href":"https:\/\/lg.yusemo.com\/index.php?rest_route=\/wp\/v2\/posts\/417\/revisions"}],"predecessor-version":[{"id":431,"href":"https:\/\/lg.yusemo.com\/index.php?rest_route=\/wp\/v2\/posts\/417\/revisions\/431"}],"wp:attachment":[{"href":"https:\/\/lg.yusemo.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=417"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lg.yusemo.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=417"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lg.yusemo.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=417"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}