{"id":1401,"date":"2023-06-27T13:54:27","date_gmt":"2023-06-27T05:54:27","guid":{"rendered":"https:\/\/xinchewhd.com.cn\/?p=1401"},"modified":"2023-06-27T13:54:27","modified_gmt":"2023-06-27T05:54:27","slug":"%e8%b6%85%e8%af%a6%e7%bb%86%e7%9a%84java-io%e7%b1%bb%e8%ae%b2%e8%a7%a3%e8%bf%91%e4%b8%89%e4%b8%87%e5%ad%97","status":"publish","type":"post","link":"https:\/\/xinchewhd.com.cn\/index.php\/java\/%e8%b6%85%e8%af%a6%e7%bb%86%e7%9a%84java-io%e7%b1%bb%e8%ae%b2%e8%a7%a3%e8%bf%91%e4%b8%89%e4%b8%87%e5%ad%97\/","title":{"rendered":"\u8d85\u8be6\u7ec6\u7684JAVA IO\u7c7b\u8bb2\u89e3(\u8fd1\u4e09\u4e07\u5b57)"},"content":{"rendered":"<div class='wxsyncmain'>\n<section data-tool=\"mdnice\u7f16\u8f91\u5668\" data-website=\"https:\/\/www.mdnice.com\" style=\"font-size: 16px;white-space: normal;color: black;padding-right: 10px;padding-left: 10px;word-break: break-word;word-wrap: break-word;text-align: left;line-height: 1.25;font-family: Optima-Regular, Optima, PingFangTC-Light, PingFangSC-light, PingFangTC-light;letter-spacing: 2px;background-image: linear-gradient(90deg, rgba(50, 0, 0, 0.05) 3%, rgba(0, 0, 0, 0) 3%), linear-gradient(360deg, rgba(50, 0, 0, 0.05) 3%, rgba(0, 0, 0, 0) 3%);background-size: 20px 20px;background-position: center center;\">\n<h1 data-tool=\"mdnice\u7f16\u8f91\u5668\" style=\"margin-top: 30px;margin-bottom: 15px;font-weight: bold;font-size: 25px;\"><span style=\"display: inline-block;color: rgb(119, 48, 152);\">Java IO\u7c7b<\/span><\/h1>\n<h2 data-tool=\"mdnice\u7f16\u8f91\u5668\" style=\"font-weight: bold;font-size: 22px;margin-top: 20px;margin-right: 10px;\"><span style=\"font-size: 18px;display: inline-block;padding-left: 10px;border-left-width: 5px;border-left-style: solid;border-left-color: rgb(145, 109, 213);\">\u524d\u8a00<\/span><\/h2>\n<p data-tool=\"mdnice\u7f16\u8f91\u5668\" style=\"padding-top: 8px;padding-bottom: 8px;line-height: 26px;margin-top: 10px;margin-bottom: 10px;font-size: 14px;word-spacing: 2px;\">\u5927\u5bb6\u597d\uff0c\u4e00\u76f4\u4ee5\u6765\u6211\u90fd\u672c\u7740 <span style=\"color:#3eaf7c;\">\u7528\u6700\u901a\u4fd7\u7684\u8bdd\u7406\u89e3\u6838\u5fc3\u7684\u77e5\u8bc6\u70b9<\/span>\uff0c \u6211\u8ba4\u4e3a\u6240\u6709\u7684\u96be\u70b9\u90fd\u79bb\u4e0d\u5f00&nbsp;<strong style=\"color: rgb(145, 109, 213);\">\u300c<span style=\"color:#3eaf7c;\">\u57fa\u7840\u77e5\u8bc6<\/span>\u300d<\/strong>&nbsp;\u7684\u94fa\u57ab<\/p>\n<section class=\"mp_profile_iframe_wrp\"><mpprofile class=\"js_uneditable custom_select_card mp_profile_iframe\" data-pluginname=\"mpprofile\" data-id=\"MzU4NDcxOTM3OQ==\" data-headimg=\"http:\/\/mmbiz.qpic.cn\/mmbiz_png\/dDva6rRBQ2CdNqsbX0ZOtVheUHGoTtib0icQ7L0cw9gRuTRGBLBN8vicep6dA8aLicWomyRCSTIZQx51icvaYhg6EHg\/0?wx_fmt=png\" data-nickname=\"\u7a0b\u5e8f\u5458\u76ae\u5361\u79cb\" data-alias=\"weqdnj\" data-signature=\"\u5206\u4eab\u66f4\u591a\u597d\u73a9\u6709\u8da3\u7684\u7f16\u7a0b\u77e5\u8bc6~\" data-from=\"0\"><\/mpprofile><\/section>\n<h2 data-tool=\"mdnice\u7f16\u8f91\u5668\" style=\"font-weight: bold;font-size: 22px;margin-top: 20px;margin-right: 10px;\"><span style=\"font-size: 18px;display: inline-block;padding-left: 10px;border-left-width: 5px;border-left-style: solid;border-left-color: rgb(145, 109, 213);\">\u80cc\u666f<\/span><\/h2>\n<p data-tool=\"mdnice\u7f16\u8f91\u5668\" style=\"padding-top: 8px;padding-bottom: 8px;line-height: 26px;margin-top: 10px;margin-bottom: 10px;font-size: 14px;word-spacing: 2px;\">\u672c\u8282\u7ed9\u5927\u5bb6\u8bb2\u8bb2&nbsp;<strong style=\"color: rgb(145, 109, 213);\">\u300c<span style=\"color:#3eaf7c;\">Java\u7684IO\u7c7b<\/span>\u300d<\/strong>&nbsp;\uff0c\u4e4b\u524d\u6211\u4eec\u5b66\u4e60\u7684\u77e5\u8bc6\u90fd\u662f\u81ea\u5df1\u8ddf\u81ea\u5df1\u73a9\uff0c\u6ca1\u6709\u6d89\u53ca\u5230\u8ddf\u7cfb\u7edf\u4ea4\u4e92\uff0c\u4e3e\u4e2a\u4f8b\u5b50\u6bd4\u5982\u6211\u4eec\u9700\u8981\u5c06\u6211\u4eec\u5b9a\u4e49\u7684\u4e00\u6bb5\u6587\u5b57\u4fdd\u5b58\u5230\u6587\u4ef6\u4e2d\uff0c\u90a3\u4e48\u5982\u4f55\u505a\u5462,\u8fd9\u5c31\u662f\u672c\u8282\u6240\u8bb2\u7684\u4e3b\u8981\u5185\u5bb9JAVA\u7684&nbsp;<strong style=\"color: rgb(145, 109, 213);\">\u300c<span style=\"color:#3eaf7c;\">IO<\/span>\u300d<\/strong>&nbsp;\u76f8\u5173\u64cd\u4f5c~<\/p>\n<p data-tool=\"mdnice\u7f16\u8f91\u5668\" style=\"padding-top: 8px;padding-bottom: 8px;line-height: 26px;margin-top: 10px;margin-bottom: 10px;font-size: 14px;word-spacing: 2px;\"><strong style=\"color: rgb(145, 109, 213);\">\u300c\u957f\u6587\u9884\u8b66 \u8010\u5fc3\u770b\u5b8c\u54e6 ~\u300d<\/strong><\/p>\n<h2 data-tool=\"mdnice\u7f16\u8f91\u5668\" style=\"font-weight: bold;font-size: 22px;margin-top: 20px;margin-right: 10px;\"><span style=\"font-size: 18px;display: inline-block;padding-left: 10px;border-left-width: 5px;border-left-style: solid;border-left-color: rgb(145, 109, 213);\">\u4ec0\u4e48\u662fIO<\/span><\/h2>\n<p data-tool=\"mdnice\u7f16\u8f91\u5668\" style=\"padding-top: 8px;padding-bottom: 8px;line-height: 26px;margin-top: 10px;margin-bottom: 10px;font-size: 14px;word-spacing: 2px;\">\u5728\u5b66\u4e60Java IO\u64cd\u4f5c\u4e4b\u524d\uff0c\u5148\u7406\u89e3\u4e00\u4e0b\u4ec0\u4e48\u662f&nbsp;<strong style=\"color: rgb(145, 109, 213);\">\u300c<span style=\"color:#3eaf7c;\">IO<\/span>\u300d<\/strong>&nbsp;\u64cd\u4f5c\uff1f<\/p>\n<p data-tool=\"mdnice\u7f16\u8f91\u5668\" style=\"padding-top: 8px;padding-bottom: 8px;line-height: 26px;margin-top: 10px;margin-bottom: 10px;font-size: 14px;word-spacing: 2px;\">\u4e4b\u524d\u6211\u4eec\u5b66\u4e60Java\u8bed\u6cd5\u7684\u65f6\u5019\uff0c\u6bd4\u5982\u547d\u540d\u53d8\u91cf\uff0c\u8c03\u7528\u7c7b\u65b9\u6cd5\u6267\u884c\u4e00\u4e9b\u8ba1\u7b97\u7b49\u7b49\uff0c\u8fd9\u4e9b\u5176\u5b9e\u90fd\u662f\u5728\u8ba1\u7b97\u673a\u5185\u5b58\u91cc\u73a9\u7684\u3002\u5f88\u663e\u7136\u5728\u6211\u4eec\u5e73\u65f6\u4f7f\u7528\u7684\u4e00\u4e9b\u8f6f\u4ef6\uff0c\u5b83\u4eec\u90fd\u9700\u8981\u8ddf\u5404\u79cd\u5404\u6837\u7684\u786c\u4ef6\u6253\u4ea4\u9053\uff0c\u6bd4\u5982\u89c6\u9891\u901a\u8bdd\u5c31\u9700\u8981\u8ddf\u6211\u4eec\u7684\u6444\u50cf\u5934\u3001\u97f3\u9891\u4e4b\u7c7b\u7684\u786c\u4ef6\u8fdb\u884c\u4ea4\u4e92\uff0c\u518d\u6bd4\u5982\u6211\u4eec\u6253\u5b57\u7684\u952e\u76d8\uff0c\u7535\u8111\u7684\u663e\u793a\u5668\u7b49\uff0c\u8fd9\u4e9b\u901a\u5e38\u53eb\u505a\u5916\u8bbe\u3002<\/p>\n<p data-tool=\"mdnice\u7f16\u8f91\u5668\" style=\"padding-top: 8px;padding-bottom: 8px;line-height: 26px;margin-top: 10px;margin-bottom: 10px;font-size: 14px;word-spacing: 2px;\">\u8ba1\u7b97\u673a\u8bed\u8a00\u901a\u5e38\u90fd\u8981\u63d0\u4f9b\u4e0e\u5b83\u4eec\u64cd\u4f5c\u7684\u63a5\u53e3\uff0c\u6240\u4ee5\u5c31\u5f15\u7533\u4e86&nbsp;<strong style=\"color: rgb(145, 109, 213);\">\u300c<span style=\"color:#3eaf7c;\">IO\u6846\u67b6<\/span>\u300d<\/strong>&nbsp;\u8fd9\u4e48\u4e2a\u4e1c\u897f\u3002\u90a3\u4e48\u5230\u5e95\u662f\u600e\u4e48\u8fdb\u884c\u4ea4\u4e92\u7684\u5462\uff1f\u4e3e\u4e2a\u952e\u76d8\u7684\u4f8b\u5b50\uff0c\u901a\u5e38\u6211\u4eec\u7684\u952e\u76d8\u90fd\u901a\u8fc7\u4e00\u4e2aUSB\u53e3\uff0c\u90a3\u4e48\u8fde\u7740\u5b83\u7684\u662f\u6570\u636e\u7ebf\uff0c\u5b83\u4eec\u7684\u4ea4\u4e92\u662f\u901a\u8fc7\u6570\u636e\u7ebf\u8fdb\u884c\u6570\u636e\u7684\u4f20\u8f93\uff0c\u5f53\u7136\uff0c\u5982\u679c\u662f\u65e0\u7ebf\u8bbe\u5907\uff0c\u90a3\u4e48\u901a\u5e38\u90fd\u662f\u901a\u8fc7\u84dd\u7259\u4f20\u8f93\u6570\u636e\u3002\u90a3\u4e48\u8fd9\u4e2a\u6570\u636e\u7684\u5f62\u5f0f\u662f\u600e\u4e48\u6837\u7684\u5462\uff1f\u5b83\u5c31\u662f <span style=\"color:#3eaf7c;\">\u6bd4\u7279\u6d41<\/span>\uff0c\u5355\u4f4d\u5c31\u662f\u6211\u4eec\u5e38\u8bf4\u7684\u5b57\u8282\uff0c\u901a\u5e38\u67098\u4f4d0\u62161\u7ec4\u6210\u7684\u4e00\u6bb5\u6570\u636e\u3002<\/p>\n<p data-tool=\"mdnice\u7f16\u8f91\u5668\" style=\"padding-top: 8px;padding-bottom: 8px;line-height: 26px;margin-top: 10px;margin-bottom: 10px;font-size: 14px;word-spacing: 2px;\">\u65e2\u7136\u6709\u4f20\u8f93\uff0c\u597d\u6bd4\u81ea\u6765\u6c34\u7ba1\uff0c\u6709\u8f93\u5165\u7aef\u548c\u8f93\u51fa\u7aef, \u90a3\u4e48\u80af\u5b9a\u6709&nbsp;<strong style=\"color: rgb(145, 109, 213);\">\u300c<span style=\"color:#3eaf7c;\">\u8f93\u5165\u6d41(InputStream)<\/span>\u300d<\/strong>&nbsp;\u548c&nbsp;<strong style=\"color: rgb(145, 109, 213);\">\u300c<span style=\"color:#3eaf7c;\">\u8f93\u51fa\u6d41(OutputStream)<\/span>\u300d<\/strong>,\u8fd8\u662f\u521a\u521a\u7684\u4f8b\u5b50\uff0c\u90a3\u4e48\u8f93\u5165\u7aef\u548c\u8f93\u51fa\u7aef\u5206\u522b\u662f\u4ec0\u4e48\u5462\uff1f<\/p>\n<p data-tool=\"mdnice\u7f16\u8f91\u5668\" style=\"padding-top: 8px;padding-bottom: 8px;line-height: 26px;margin-top: 10px;margin-bottom: 10px;font-size: 14px;word-spacing: 2px;\">\u5176\u5b9e\u4e5f\u5f88\u597d\u5224\u65ad\uff0c\u5b83\u65e2\u7136\u662f\u4e00\u4e2a\u6709\u65b9\u5411\u6027\u7684\uff0c\u90a3\u4e48&nbsp;<strong style=\"color: rgb(145, 109, 213);\">\u300c<span style=\"color:#3eaf7c;\">\u8f93\u5165\u6d41(InputStream)<\/span>\u300d<\/strong>&nbsp;\u5c31\u662f\u7531\u5916\u5411\u5185\uff0c&nbsp;<strong style=\"color: rgb(145, 109, 213);\">\u300c<span style=\"color:#3eaf7c;\">\u8f93\u51fa\u6d41(OutputStream)<\/span>\u300d<\/strong>&nbsp;\u5c31\u662f\u7531\u5185\u5411\u5916\u3002\u90a3\u4e48\u4f8b\u5b50\u4e2d\u7684\u952e\u76d8\u5c31\u662f\u8f93\u5165\u8bbe\u5907\uff0c \u8ba1\u7b97\u673a\u5c31\u662f\u8f93\u51fa\u7aef\uff0c\u7ec6\u8bb2\u5c31\u662f\u6570\u636e\u901a\u8fc7\u5185\u5b58\u5411\u5916\u8f93\u51fa\u3002\u597d\u4e86\uff0c\u6709\u4e86\u8fd9\u4e9b\u7684\u57fa\u672c\u6982\u5ff5\uff0c\u6211\u4eec\u5728\u770bJava\u7684&nbsp;<strong style=\"color: rgb(145, 109, 213);\">\u300c<span style=\"color:#3eaf7c;\">IO<\/span>\u300d<\/strong>&nbsp;\u76f8\u5173\u64cd\u4f5c\u5c31\u6709\u4e00\u4e2a\u5f88\u597d\u7684\u7406\u89e3\u4e86\u3002<\/p>\n<p data-tool=\"mdnice\u7f16\u8f91\u5668\" style=\"padding-top: 8px;padding-bottom: 8px;line-height: 26px;margin-top: 10px;margin-bottom: 10px;font-size: 14px;word-spacing: 2px;\">\u8fd8\u662f\u90a3\u53e5\u8bdd\uff0c\u4e0d\u8981\u6b7b\u8bb0\u786c\u80cc\u76f8\u5173\u7c7b\u548c\u65b9\u6cd5\uff0c\u8981\u77e5\u9053\u5b83\u7684\u539f\u7406\uff0c\u4e0b\u9762\u6211\u4eec\u5c31\u8fdb\u5165\u6b63\u9898~<\/p>\n<h2 data-tool=\"mdnice\u7f16\u8f91\u5668\" style=\"font-weight: bold;font-size: 22px;margin-top: 20px;margin-right: 10px;\"><span style=\"font-size: 18px;display: inline-block;padding-left: 10px;border-left-width: 5px;border-left-style: solid;border-left-color: rgb(145, 109, 213);\">File\u64cd\u4f5c<\/span><\/h2>\n<p data-tool=\"mdnice\u7f16\u8f91\u5668\" style=\"padding-top: 8px;padding-bottom: 8px;line-height: 26px;margin-top: 10px;margin-bottom: 10px;font-size: 14px;word-spacing: 2px;\"><strong style=\"color: rgb(145, 109, 213);\">\u300c<span style=\"color:#3eaf7c;\">File<\/span>\u300d<\/strong>&nbsp;\u5373\u6587\u4ef6\u64cd\u4f5c\uff0c\u901a\u5e38\u548c\u8ba1\u7b97\u673a\u7684\u78c1\u76d8\u6253\u4ea4\u9053\uff0c\u8fd9\u4e5f\u662f\u6700\u57fa\u672c\u7684\u64cd\u4f5c\u4e86\u3002\u5728\u6211\u4eec\u5e73\u65f6\u64cd\u4f5c\u6587\u4ef6\u7684\u65f6\u5019\uff0c\u6709\u6587\u4ef6\u5939\u548c\u6587\u4ef6\u64cd\u4f5c\uff0c\u57fa\u672c\u7684\u521b\u5efa\u3001\u4fee\u6539\u3001\u5220\u9664\u7b49\u64cd\u4f5c\uff0c\u5728Java\u4e2d\u662f&nbsp;<strong style=\"color: rgb(145, 109, 213);\">\u300c<span style=\"color:#3eaf7c;\">File<\/span>\u300d<\/strong>&nbsp;\u7c7b\u53bb\u505a\u7684\u4e00\u4e9b\u76f8\u5173\u64cd\u4f5c,\u6240\u4ee5\u6211\u4eec\u9700\u8981\u5148\u5b9e\u4f8b\u5316\u5b83\u3002<\/p>\n<h3 data-tool=\"mdnice\u7f16\u8f91\u5668\" style=\"margin-top: 30px;margin-bottom: 15px;font-weight: bold;text-align: center;\"><span style=\"border-bottom-width: 2px;border-bottom-style: solid;border-bottom-color: rgb(216, 156, 246);\">\u6587\u4ef6\u64cd\u4f5c<\/span><\/h3>\n<p data-tool=\"mdnice\u7f16\u8f91\u5668\" style=\"padding-top: 8px;padding-bottom: 8px;line-height: 26px;margin-top: 10px;margin-bottom: 10px;font-size: 14px;word-spacing: 2px;\">\u5728\u5f53\u524d\u76ee\u5f55\u521b\u5efa\u4e00\u4e2a\u6587\u4ef6<\/p>\n<pre data-tool=\"mdnice\u7f16\u8f91\u5668\" style=\"margin-top: 10px;margin-bottom: 10px;border-top-left-radius: 5px;border-top-right-radius: 5px;border-bottom-right-radius: 5px;border-bottom-left-radius: 5px;box-shadow: rgba(0, 0, 0, 0.55) 0px 2px 10px;\"><span style=\"display: block;background-image: url('https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2023\/05\/20230528042704988.jpeg');height: 30px;width: 749px;background-size: 40px;background-color: rgb(40, 44, 52);margin-bottom: -7px;border-top-left-radius: 5px;border-top-right-radius: 5px;border-bottom-right-radius: 5px;border-bottom-left-radius: 5px;background-position: 10px 10px;background-repeat: no-repeat no-repeat;\"><\/span><code style=\"overflow-x: auto;padding: 15px 16px 16px;color: rgb(171, 178, 191);display: -webkit-box;font-family: &quot;Operator Mono&quot;, Consolas, Monaco, Menlo, monospace;font-size: 12px;background-color: rgb(40, 44, 52);border-top-left-radius: 5px;border-top-right-radius: 5px;border-bottom-right-radius: 5px;border-bottom-left-radius: 5px;\">File&nbsp;txt&nbsp;=&nbsp;<span style=\"color: rgb(198, 120, 221);line-height: 26px;\">new<\/span>&nbsp;File(<span style=\"color: rgb(152, 195, 121);line-height: 26px;\">\"test.txt\"<\/span>);<br  \/><br  \/><span style=\"color: rgb(92, 99, 112);font-style: italic;line-height: 26px;\">\/\/&nbsp;\u5224\u65ad\u662f\u5426\u5b58\u5728<\/span><br  \/><span style=\"color: rgb(198, 120, 221);line-height: 26px;\">if<\/span>(txt.exists())&nbsp;{<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;Log.info(<span style=\"color: rgb(152, 195, 121);line-height: 26px;\">\"File&nbsp;\u5b58\u5728\"<\/span>);<br  \/>}<span style=\"color: rgb(198, 120, 221);line-height: 26px;\">else<\/span>&nbsp;{<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"color: rgb(198, 120, 221);line-height: 26px;\">try<\/span>&nbsp;{<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"color: rgb(92, 99, 112);font-style: italic;line-height: 26px;\">\/\/&nbsp;\u521b\u5efa\u6587\u4ef6<\/span><br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"color: rgb(198, 120, 221);line-height: 26px;\">if<\/span>(txt.createNewFile())<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Log.info(<span style=\"color: rgb(152, 195, 121);line-height: 26px;\">\"\u521b\u5efa\u6210\u529f\"<\/span>);<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;<span style=\"color: rgb(198, 120, 221);line-height: 26px;\">catch<\/span>(IOException&nbsp;e)&nbsp;{<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Log.info(<span style=\"color: rgb(152, 195, 121);line-height: 26px;\">\"err--&gt;\"<\/span>&nbsp;+&nbsp;e.getMessage());<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;}<br  \/>}<br  \/><br  \/><\/code><\/pre>\n<p data-tool=\"mdnice\u7f16\u8f91\u5668\" style=\"padding-top: 8px;padding-bottom: 8px;line-height: 26px;margin-top: 10px;margin-bottom: 10px;font-size: 14px;word-spacing: 2px;\">\u91cd\u547d\u540d\u6587\u4ef6:<\/p>\n<pre data-tool=\"mdnice\u7f16\u8f91\u5668\" style=\"margin-top: 10px;margin-bottom: 10px;border-top-left-radius: 5px;border-top-right-radius: 5px;border-bottom-right-radius: 5px;border-bottom-left-radius: 5px;box-shadow: rgba(0, 0, 0, 0.55) 0px 2px 10px;\"><span style=\"display: block;background-image: url('https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2023\/05\/20230528042704988.jpeg');height: 30px;width: 749px;background-size: 40px;background-color: rgb(40, 44, 52);margin-bottom: -7px;border-top-left-radius: 5px;border-top-right-radius: 5px;border-bottom-right-radius: 5px;border-bottom-left-radius: 5px;background-position: 10px 10px;background-repeat: no-repeat no-repeat;\"><\/span><code style=\"overflow-x: auto;padding: 15px 16px 16px;color: rgb(171, 178, 191);display: -webkit-box;font-family: &quot;Operator Mono&quot;, Consolas, Monaco, Menlo, monospace;font-size: 12px;background-color: rgb(40, 44, 52);border-top-left-radius: 5px;border-top-right-radius: 5px;border-bottom-right-radius: 5px;border-bottom-left-radius: 5px;\"><span style=\"color: rgb(198, 120, 221);line-height: 26px;\">if<\/span>(txt.exists())&nbsp;{<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"color: rgb(198, 120, 221);line-height: 26px;\">if<\/span>(txt.renameTo(<span style=\"color: rgb(198, 120, 221);line-height: 26px;\">new<\/span>&nbsp;File(<span style=\"color: rgb(152, 195, 121);line-height: 26px;\">\"test1.txt\"<\/span>)))<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Log.info(<span style=\"color: rgb(152, 195, 121);line-height: 26px;\">\"\u91cd\u547d\u540d\u6210\u529f\"<\/span>);<br  \/><br  \/>}<br  \/><\/code><\/pre>\n<p data-tool=\"mdnice\u7f16\u8f91\u5668\" style=\"padding-top: 8px;padding-bottom: 8px;line-height: 26px;margin-top: 10px;margin-bottom: 10px;font-size: 14px;word-spacing: 2px;\">\u5220\u9664\u6587\u4ef6:<\/p>\n<pre data-tool=\"mdnice\u7f16\u8f91\u5668\" style=\"margin-top: 10px;margin-bottom: 10px;border-top-left-radius: 5px;border-top-right-radius: 5px;border-bottom-right-radius: 5px;border-bottom-left-radius: 5px;box-shadow: rgba(0, 0, 0, 0.55) 0px 2px 10px;\"><span style=\"display: block;background-image: url('https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2023\/05\/20230528042704988.jpeg');height: 30px;width: 749px;background-size: 40px;background-color: rgb(40, 44, 52);margin-bottom: -7px;border-top-left-radius: 5px;border-top-right-radius: 5px;border-bottom-right-radius: 5px;border-bottom-left-radius: 5px;background-position: 10px 10px;background-repeat: no-repeat no-repeat;\"><\/span><code style=\"overflow-x: auto;padding: 15px 16px 16px;color: rgb(171, 178, 191);display: -webkit-box;font-family: &quot;Operator Mono&quot;, Consolas, Monaco, Menlo, monospace;font-size: 12px;background-color: rgb(40, 44, 52);border-top-left-radius: 5px;border-top-right-radius: 5px;border-bottom-right-radius: 5px;border-bottom-left-radius: 5px;\">&nbsp;<span style=\"color: rgb(198, 120, 221);line-height: 26px;\">if<\/span>(txt.exists())&nbsp;{<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"color: rgb(198, 120, 221);line-height: 26px;\">if<\/span>(txt.delete())<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Log.info(<span style=\"color: rgb(152, 195, 121);line-height: 26px;\">\"txt&nbsp;\u5220\u9664\u6210\u529f\"<\/span>);<br  \/>&nbsp;&nbsp;}<br  \/><\/code><\/pre>\n<p data-tool=\"mdnice\u7f16\u8f91\u5668\" style=\"padding-top: 8px;padding-bottom: 8px;line-height: 26px;margin-top: 10px;margin-bottom: 10px;font-size: 14px;word-spacing: 2px;\">\u521b\u5efa\u6587\u4ef6\u5939:<\/p>\n<pre data-tool=\"mdnice\u7f16\u8f91\u5668\" style=\"margin-top: 10px;margin-bottom: 10px;border-top-left-radius: 5px;border-top-right-radius: 5px;border-bottom-right-radius: 5px;border-bottom-left-radius: 5px;box-shadow: rgba(0, 0, 0, 0.55) 0px 2px 10px;\"><span style=\"display: block;background-image: url('https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2023\/05\/20230528042704988.jpeg');height: 30px;width: 749px;background-size: 40px;background-color: rgb(40, 44, 52);margin-bottom: -7px;border-top-left-radius: 5px;border-top-right-radius: 5px;border-bottom-right-radius: 5px;border-bottom-left-radius: 5px;background-position: 10px 10px;background-repeat: no-repeat no-repeat;\"><\/span><code style=\"overflow-x: auto;padding: 15px 16px 16px;color: rgb(171, 178, 191);display: -webkit-box;font-family: &quot;Operator Mono&quot;, Consolas, Monaco, Menlo, monospace;font-size: 12px;background-color: rgb(40, 44, 52);border-top-left-radius: 5px;border-top-right-radius: 5px;border-bottom-right-radius: 5px;border-bottom-left-radius: 5px;\">&nbsp;File&nbsp;dir&nbsp;=&nbsp;<span style=\"color: rgb(198, 120, 221);line-height: 26px;\">new<\/span>&nbsp;File(<span style=\"color: rgb(152, 195, 121);line-height: 26px;\">\"test\"<\/span>);<br  \/>&nbsp;&nbsp;<span style=\"color: rgb(198, 120, 221);line-height: 26px;\">if<\/span>(!dir.exists())&nbsp;{<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"color: rgb(198, 120, 221);line-height: 26px;\">if<\/span>(dir.mkdir())<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Log.info(<span style=\"color: rgb(152, 195, 121);line-height: 26px;\">\"\u6587\u4ef6\u5939\u521b\u5efa\u6210\u529f\"<\/span>);<br  \/><br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"color: rgb(92, 99, 112);font-style: italic;line-height: 26px;\">\/\/&nbsp;\u5224\u65ad\u662f\u5426\u662f\u6587\u4ef6\u5939<\/span><br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"color: rgb(198, 120, 221);line-height: 26px;\">if<\/span>(dir.isDirectory())<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Log.info(<span style=\"color: rgb(152, 195, 121);line-height: 26px;\">\"\u662f\u6587\u4ef6\u5939\"<\/span>);<br  \/>&nbsp;&nbsp;}<br  \/><\/code><\/pre>\n<p data-tool=\"mdnice\u7f16\u8f91\u5668\" style=\"padding-top: 8px;padding-bottom: 8px;line-height: 26px;margin-top: 10px;margin-bottom: 10px;font-size: 14px;word-spacing: 2px;\">\u521b\u5efa\u5d4c\u5957\u6587\u4ef6\u5939:<\/p>\n<pre data-tool=\"mdnice\u7f16\u8f91\u5668\" style=\"margin-top: 10px;margin-bottom: 10px;border-top-left-radius: 5px;border-top-right-radius: 5px;border-bottom-right-radius: 5px;border-bottom-left-radius: 5px;box-shadow: rgba(0, 0, 0, 0.55) 0px 2px 10px;\"><span style=\"display: block;background-image: url('https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2023\/05\/20230528042704988.jpeg');height: 30px;width: 749px;background-size: 40px;background-color: rgb(40, 44, 52);margin-bottom: -7px;border-top-left-radius: 5px;border-top-right-radius: 5px;border-bottom-right-radius: 5px;border-bottom-left-radius: 5px;background-position: 10px 10px;background-repeat: no-repeat no-repeat;\"><\/span><code style=\"overflow-x: auto;padding: 15px 16px 16px;color: rgb(171, 178, 191);display: -webkit-box;font-family: &quot;Operator Mono&quot;, Consolas, Monaco, Menlo, monospace;font-size: 12px;background-color: rgb(40, 44, 52);border-top-left-radius: 5px;border-top-right-radius: 5px;border-bottom-right-radius: 5px;border-bottom-left-radius: 5px;\"><span style=\"color: rgb(198, 120, 221);line-height: 26px;\">if<\/span>(!dir1.exists())&nbsp;{<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"color: rgb(198, 120, 221);line-height: 26px;\">if<\/span>(dir1.mkdirs())<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Log.info(<span style=\"color: rgb(152, 195, 121);line-height: 26px;\">\"\u6587\u4ef6\u5939\u521b\u5efa\u6210\u529f1\"<\/span>);<br  \/><br  \/>&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"color: rgb(92, 99, 112);font-style: italic;line-height: 26px;\">\/\/&nbsp;\u5224\u65ad\u662f\u5426\u662f\u6587\u4ef6\u5939<\/span><br  \/>&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"color: rgb(198, 120, 221);line-height: 26px;\">if<\/span>(dir1.isDirectory())<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Log.info(<span style=\"color: rgb(152, 195, 121);line-height: 26px;\">\"\u662f\u6587\u4ef6\u59391\"<\/span>);<br  \/>}<br  \/><\/code><\/pre>\n<p data-tool=\"mdnice\u7f16\u8f91\u5668\" style=\"padding-top: 8px;padding-bottom: 8px;line-height: 26px;margin-top: 10px;margin-bottom: 10px;font-size: 14px;word-spacing: 2px;\">\u5c5e\u6027\u76f8\u5173\u64cd\u4f5c:<\/p>\n<pre data-tool=\"mdnice\u7f16\u8f91\u5668\" style=\"margin-top: 10px;margin-bottom: 10px;border-top-left-radius: 5px;border-top-right-radius: 5px;border-bottom-right-radius: 5px;border-bottom-left-radius: 5px;box-shadow: rgba(0, 0, 0, 0.55) 0px 2px 10px;\"><span style=\"display: block;background-image: url('https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2023\/05\/20230528042704988.jpeg');height: 30px;width: 749px;background-size: 40px;background-color: rgb(40, 44, 52);margin-bottom: -7px;border-top-left-radius: 5px;border-top-right-radius: 5px;border-bottom-right-radius: 5px;border-bottom-left-radius: 5px;background-position: 10px 10px;background-repeat: no-repeat no-repeat;\"><\/span><code style=\"overflow-x: auto;padding: 15px 16px 16px;color: rgb(171, 178, 191);display: -webkit-box;font-family: &quot;Operator Mono&quot;, Consolas, Monaco, Menlo, monospace;font-size: 12px;background-color: rgb(40, 44, 52);border-top-left-radius: 5px;border-top-right-radius: 5px;border-bottom-right-radius: 5px;border-bottom-left-radius: 5px;\">&nbsp;&nbsp;File&nbsp;txt1&nbsp;=&nbsp;<span style=\"color: rgb(198, 120, 221);line-height: 26px;\">new<\/span>&nbsp;File(<span style=\"color: rgb(152, 195, 121);line-height: 26px;\">\"test1.txt\"<\/span>);<br  \/>&nbsp;&nbsp;Log.info(<span style=\"color: rgb(152, 195, 121);line-height: 26px;\">\"\u83b7\u53d6\u7236\u8def\u5f84&nbsp;----&gt;\"<\/span>&nbsp;+&nbsp;<span style=\"color: rgb(198, 120, 221);line-height: 26px;\">new<\/span>&nbsp;File(txt1.getAbsolutePath()).getParent());<br  \/><br  \/>&nbsp;&nbsp;Log.info(<span style=\"color: rgb(152, 195, 121);line-height: 26px;\">\"\u6587\u4ef6\u5927\u5c0f----&gt;\"<\/span>&nbsp;+&nbsp;txt1.length()&nbsp;+&nbsp;<span style=\"color: rgb(152, 195, 121);line-height: 26px;\">\"byte\"<\/span>);&nbsp;<span style=\"color: rgb(92, 99, 112);font-style: italic;line-height: 26px;\">\/\/&nbsp;0&nbsp;byte<\/span><br  \/><br  \/>&nbsp;&nbsp;Log.info(<span style=\"color: rgb(152, 195, 121);line-height: 26px;\">\"\u6587\u4ef6\u662f\u5426\u9690\u85cf-----&gt;\"<\/span>&nbsp;+&nbsp;txt1.isHidden());&nbsp;<span style=\"color: rgb(92, 99, 112);font-style: italic;line-height: 26px;\">\/\/&nbsp;false<\/span><br  \/><br  \/>&nbsp;&nbsp;Log.info(<span style=\"color: rgb(152, 195, 121);line-height: 26px;\">\"\u6587\u4ef6\u662f\u5426\u53ef\u8bfb-----&gt;\"<\/span>&nbsp;+&nbsp;txt1.canRead());&nbsp;<span style=\"color: rgb(92, 99, 112);font-style: italic;line-height: 26px;\">\/\/&nbsp;true<\/span><br  \/><br  \/>&nbsp;&nbsp;Log.info(<span style=\"color: rgb(152, 195, 121);line-height: 26px;\">\"\u6587\u4ef6\u662f\u5426\u53ef\u5199-----&gt;\"<\/span>&nbsp;+&nbsp;txt1.canWrite());&nbsp;<span style=\"color: rgb(92, 99, 112);font-style: italic;line-height: 26px;\">\/\/&nbsp;true<\/span><br  \/><br  \/>&nbsp;&nbsp;Log.info(<span style=\"color: rgb(152, 195, 121);line-height: 26px;\">\"\u83b7\u53d6\u6587\u4ef6\u8def\u5f84----&gt;\"<\/span>&nbsp;+&nbsp;txt1.getPath());&nbsp;<span style=\"color: rgb(92, 99, 112);font-style: italic;line-height: 26px;\">\/\/&nbsp;test1.txt<\/span><br  \/><br  \/>&nbsp;&nbsp;<span style=\"color: rgb(92, 99, 112);font-style: italic;line-height: 26px;\">\/\/&nbsp;\u5c5e\u6027\u8bbe\u7f6e<\/span><br  \/>&nbsp;&nbsp;txt1.setReadable(<span style=\"color: rgb(198, 120, 221);line-height: 26px;\">false<\/span>);&nbsp;&nbsp;<span style=\"color: rgb(92, 99, 112);font-style: italic;line-height: 26px;\">\/\/&nbsp;\u662f\u5426\u53ef\u8bfb<\/span><br  \/>&nbsp;&nbsp;txt1.setWritable(<span style=\"color: rgb(198, 120, 221);line-height: 26px;\">false<\/span>);&nbsp;<span style=\"color: rgb(92, 99, 112);font-style: italic;line-height: 26px;\">\/\/&nbsp;\u662f\u5426\u53ef\u5199<\/span><br  \/>&nbsp;&nbsp;txt1.setExecutable(<span style=\"color: rgb(198, 120, 221);line-height: 26px;\">false<\/span>);&nbsp;<span style=\"color: rgb(92, 99, 112);font-style: italic;line-height: 26px;\">\/\/&nbsp;\u662f\u5426\u53ef\u6267\u884c<\/span><br  \/>&nbsp;&nbsp;txt1.setLastModified(<span style=\"color: rgb(198, 120, 221);line-height: 26px;\">new<\/span>&nbsp;Date().getTime());&nbsp;<span style=\"color: rgb(92, 99, 112);font-style: italic;line-height: 26px;\">\/\/&nbsp;\u6700\u540e\u4fee\u6539\u65f6\u95f4<\/span><br  \/>&nbsp;&nbsp;txt1.setReadOnly();&nbsp;<span style=\"color: rgb(92, 99, 112);font-style: italic;line-height: 26px;\">\/\/&nbsp;\u8bbe\u7f6e\u53ea\u8bfb<\/span><br  \/><\/code><\/pre>\n<p data-tool=\"mdnice\u7f16\u8f91\u5668\" style=\"padding-top: 8px;padding-bottom: 8px;line-height: 26px;margin-top: 10px;margin-bottom: 10px;font-size: 14px;word-spacing: 2px;\">\u4ee5\u4e0a\u662f\u5927\u90e8\u5206\u5e38\u7528\u7684\u6587\u4ef6\u76f8\u5173\u64cd\u4f5c ~<\/p>\n<h2 data-tool=\"mdnice\u7f16\u8f91\u5668\" style=\"font-weight: bold;font-size: 22px;margin-top: 20px;margin-right: 10px;\"><span style=\"font-size: 18px;display: inline-block;padding-left: 10px;border-left-width: 5px;border-left-style: solid;border-left-color: rgb(145, 109, 213);\">\u5b57\u8282\u64cd\u4f5c\uff1aInputStream \u548c OutputStream<\/span><\/h2>\n<p data-tool=\"mdnice\u7f16\u8f91\u5668\" style=\"padding-top: 8px;padding-bottom: 8px;line-height: 26px;margin-top: 10px;margin-bottom: 10px;font-size: 14px;word-spacing: 2px;\">\u4e0a\u8fb9\u6211\u4eec\u8bb2\u8ff0\u4e86\u6587\u4ef6\u7684\u76f8\u5173\u64cd\u4f5c\uff0c\u6211\u4eec\u521b\u5efa\u7684\u6587\u4ef6\u90fd\u662f\u7a7a\u767d\u7684\uff0c\u73b0\u5728\u9700\u8981\u6211\u4eec\u5f80\u6587\u4ef6\u91cc\u5199\u4e00\u4e9b\u6587\u5b57\u600e\u4e48\u64cd\u4f5c\u5462\uff1f\u8fd9\u5c31\u9700\u8981\u7528\u5230\u6211\u4eec\u4e4b\u524d\u8bb2\u7684&nbsp;&nbsp;<strong style=\"color: rgb(145, 109, 213);\">\u300c<span style=\"color:#3eaf7c;\">IO<\/span>\u300d<\/strong>&nbsp;\u64cd\u4f5c\u6d41\u4e86~<\/p>\n<p><readmore data-tool=\"mdnice\u7f16\u8f91\u5668\"><\/p>\n<h3 style=\"margin-top: 30px;margin-bottom: 15px;font-weight: bold;text-align: center;\"><span style=\"border-bottom-width: 2px;border-bottom-style: solid;border-bottom-color: rgb(216, 156, 246);\">\u6587\u4ef6\u590d\u5236<\/span><\/h3>\n<p style=\"padding-top: 8px;padding-bottom: 8px;line-height: 26px;margin-top: 10px;margin-bottom: 10px;font-size: 14px;word-spacing: 2px;\">\u8fd8\u662f\u4ee5\u4e00\u4e2a\u4f8b\u5b50\u6765\u8bb2\uff0c\u6211\u4eec\u590d\u5236\u4e00\u4e2a\u6587\u4ef6\uff0c\u70b9\u70b9\u9f20\u6807\u53f3\u952e\u5c31\u89e3\u51b3\u4e86\uff0c\u90a3\u4e48\u5728Java\u4e2d\uff0c\u6211\u4eec\u5982\u4f55\u4f7f\u7528\u7a0b\u5e8f\u6765\u8fdb\u884c\u6587\u4ef6\u62f7\u8d1d\u5462\uff1f<\/p>\n<p style=\"padding-top: 8px;padding-bottom: 8px;line-height: 26px;margin-top: 10px;margin-bottom: 10px;font-size: 14px;word-spacing: 2px;\">\u4e3b\u8981\u8fc7\u7a0b\u5206\u4e3a\u4ee5\u4e0b\u8fc7\u7a0b:<\/p>\n<ul style=\"margin-top: 8px;margin-bottom: 8px;padding-left: 25px;font-size: 15px;list-style-type: circle;\" class=\"list-paddingleft-2\">\n<li>\n<section style=\"margin-top: 5px;margin-bottom: 5px;line-height: 26px;color: rgb(1, 1, 1);font-size: 14px;\">\n<p style=\"padding-top: 8px;padding-bottom: 8px;line-height: 26px;color: black;margin-top: 10px;margin-bottom: 10px;word-spacing: 2px;\">\u5b9a\u4e49\u8f93\u5165\u7684\u6587\u4ef6\u8def\u5f84\u548c\u8f93\u51fa\u7684\u6587\u4ef6\u8def\u5f84\uff08\u7531\u8def\u5f84+\u6587\u4ef6\u540d\u542b\u6587\u4ef6\u683c\u5f0f\u540e\u7f00\u7ec4\u6210\uff09<\/p>\n<\/section>\n<\/li>\n<li>\n<section style=\"margin-top: 5px;margin-bottom: 5px;line-height: 26px;color: rgb(1, 1, 1);font-size: 14px;\">\n<p style=\"padding-top: 8px;padding-bottom: 8px;line-height: 26px;color: black;margin-top: 10px;margin-bottom: 10px;word-spacing: 2px;\">\u5b9a\u4e49&nbsp;<strong style=\"color: rgb(145, 109, 213);\">\u300c<span style=\"color:#3eaf7c;\">\u6587\u4ef6\u8f93\u5165\u6d41(FileInputStream)<\/span>\u300d<\/strong>&nbsp;\u548c&nbsp;<strong style=\"color: rgb(145, 109, 213);\">\u300c<span style=\"color:#3eaf7c;\">\u6587\u4ef6\u8f93\u51fa\u6d41(FileOutputStream)<\/span>\u300d<\/strong><\/p>\n<\/section>\n<\/li>\n<li>\n<section style=\"margin-top: 5px;margin-bottom: 5px;line-height: 26px;color: rgb(1, 1, 1);font-size: 14px;\">\n<p style=\"padding-top: 8px;padding-bottom: 8px;line-height: 26px;color: black;margin-top: 10px;margin-bottom: 10px;word-spacing: 2px;\">\u8bfb\u53d6\u6587\u4ef6\u5185\u5bb9\uff0c\u5199\u5165\u76ee\u6807\u6587\u4ef6<\/p>\n<\/section>\n<\/li>\n<li>\n<section style=\"margin-top: 5px;margin-bottom: 5px;line-height: 26px;color: rgb(1, 1, 1);font-size: 14px;\">\n<p style=\"padding-top: 8px;padding-bottom: 8px;line-height: 26px;color: black;margin-top: 10px;margin-bottom: 10px;word-spacing: 2px;\">\u5173\u95ed\u6d41\u901a\u9053<\/p>\n<\/section>\n<\/li>\n<\/ul>\n<p style=\"padding-top: 8px;padding-bottom: 8px;line-height: 26px;margin-top: 10px;margin-bottom: 10px;font-size: 14px;word-spacing: 2px;\">\u5bf9\u5e94\u7684\u4ee3\u7801\u5982\u4e0b:<\/p>\n<pre style=\"margin-top: 10px;margin-bottom: 10px;border-top-left-radius: 5px;border-top-right-radius: 5px;border-bottom-right-radius: 5px;border-bottom-left-radius: 5px;box-shadow: rgba(0, 0, 0, 0.55) 0px 2px 10px;\"><span style=\"display: block;background-image: url('https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2023\/05\/20230528042704988.jpeg');height: 30px;width: 749px;background-size: 40px;background-color: rgb(40, 44, 52);margin-bottom: -7px;border-top-left-radius: 5px;border-top-right-radius: 5px;border-bottom-right-radius: 5px;border-bottom-left-radius: 5px;background-position: 10px 10px;background-repeat: no-repeat no-repeat;\"><\/span><code style=\"overflow-x: auto;padding: 15px 16px 16px;color: rgb(171, 178, 191);display: -webkit-box;font-family: &quot;Operator Mono&quot;, Consolas, Monaco, Menlo, monospace;font-size: 12px;background-color: rgb(40, 44, 52);border-top-left-radius: 5px;border-top-right-radius: 5px;border-bottom-right-radius: 5px;border-bottom-left-radius: 5px;\">&nbsp;&nbsp;<span style=\"color: rgb(92, 99, 112);font-style: italic;line-height: 26px;\">\/**<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;\u6587\u4ef6\u590d\u5236<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;<span style=\"color: rgb(198, 120, 221);line-height: 26px;\">@param<\/span>&nbsp;src&nbsp;&nbsp;\u8f93\u5165\u7684\u6587\u4ef6\u8def\u5f84<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;<span style=\"color: rgb(198, 120, 221);line-height: 26px;\">@param<\/span>&nbsp;dest&nbsp;\u8f93\u51fa\u7684\u6587\u4ef6\u8def\u5f84<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*\/<\/span><br  \/>&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"line-height: 26px;\"><span style=\"color: rgb(198, 120, 221);line-height: 26px;\">public<\/span>&nbsp;<span style=\"color: rgb(198, 120, 221);line-height: 26px;\">static<\/span>&nbsp;<span style=\"color: rgb(198, 120, 221);line-height: 26px;\">void<\/span>&nbsp;<span style=\"color: rgb(97, 174, 238);line-height: 26px;\">copyFile<\/span><span style=\"line-height: 26px;\">(String&nbsp;src,&nbsp;String&nbsp;dest)<\/span>&nbsp;<span style=\"color: rgb(198, 120, 221);line-height: 26px;\">throws<\/span>&nbsp;IOException&nbsp;<\/span>{<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;FileInputStream&nbsp;fis&nbsp;=&nbsp;<span style=\"color: rgb(198, 120, 221);line-height: 26px;\">new<\/span>&nbsp;FileInputStream(src);<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;FileOutputStream&nbsp;oos&nbsp;=&nbsp;<span style=\"color: rgb(198, 120, 221);line-height: 26px;\">new<\/span>&nbsp;FileOutputStream(dest);<br  \/><br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"color: rgb(92, 99, 112);font-style: italic;line-height: 26px;\">\/\/&nbsp;\u521d\u59cb\u5316buffer&nbsp;\u7f13\u51b2\u533a<\/span><br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"color: rgb(198, 120, 221);line-height: 26px;\">byte<\/span>[]&nbsp;buffer&nbsp;=&nbsp;<span style=\"color: rgb(198, 120, 221);line-height: 26px;\">new<\/span>&nbsp;<span style=\"color: rgb(198, 120, 221);line-height: 26px;\">byte<\/span>[<span style=\"color: rgb(209, 154, 102);line-height: 26px;\">1024<\/span>&nbsp;*&nbsp;<span style=\"color: rgb(209, 154, 102);line-height: 26px;\">2<\/span>];<br  \/><br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"color: rgb(198, 120, 221);line-height: 26px;\">int<\/span>&nbsp;cnt;<br  \/><br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"color: rgb(92, 99, 112);font-style: italic;line-height: 26px;\">\/**<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;read()&nbsp;and&nbsp;write()<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;<span style=\"color: rgb(198, 120, 221);line-height: 26px;\">@param<\/span>&nbsp;b \u8bfb\u53d6\u6570\u636e\u7684\u7f13\u51b2\u533a\u3002&nbsp;<span style=\"color: rgb(198, 120, 221);line-height: 26px;\">@param<\/span>&nbsp;off&nbsp;\u76ee\u6807\u6570\u7ec4\u4e2d\u7684\u8d77\u59cb\u504f\u79fb\u91cf&nbsp;&lt;code&gt;b&lt;code&gt;&nbsp;<span style=\"color: rgb(198, 120, 221);line-height: 26px;\">@param<\/span>&nbsp;len \u8bfb\u53d6\u7684\u6700\u5927\u5b57\u8282\u6570\u3002<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;<span style=\"color: rgb(198, 120, 221);line-height: 26px;\">@return<\/span>&nbsp;\u8bfb\u5165\u7f13\u51b2\u533a\u7684\u603b\u5b57\u8282\u6570\uff0c\u6216\u8005&nbsp;&lt;code&gt;-1&lt;code&gt;&nbsp;\u5982\u679c\u7531\u4e8e\u5df2\u5230\u8fbe\u6587\u4ef6\u672b\u5c3e\u800c\u6ca1\u6709\u66f4\u591a\u6570\u636e\u3002<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*\/<\/span><br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"color: rgb(198, 120, 221);line-height: 26px;\">while<\/span>((cnt&nbsp;=&nbsp;fis.read(buffer,&nbsp;<span style=\"color: rgb(209, 154, 102);line-height: 26px;\">0<\/span>,&nbsp;buffer.length))&nbsp;!=&nbsp;-<span style=\"color: rgb(209, 154, 102);line-height: 26px;\">1<\/span>)&nbsp;{<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"color: rgb(92, 99, 112);font-style: italic;line-height: 26px;\">\/\/&nbsp;\u5199\u5165\u6587\u4ef6<\/span><br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;oos.write(buffer,&nbsp;<span style=\"color: rgb(209, 154, 102);line-height: 26px;\">0<\/span>,&nbsp;cnt);<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br  \/><br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"color: rgb(92, 99, 112);font-style: italic;line-height: 26px;\">\/\/&nbsp;\u5173\u95ed\u901a\u9053<\/span><br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;fis.close();<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;oos.close();<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;}<br  \/><\/code><\/pre>\n<h2 style=\"font-weight: bold;font-size: 22px;margin-top: 20px;margin-right: 10px;\"><span style=\"font-size: 18px;display: inline-block;padding-left: 10px;border-left-width: 5px;border-left-style: solid;border-left-color: rgb(145, 109, 213);\">\u5b57\u7b26\u64cd\u4f5c<\/span><\/h2>\n<p style=\"padding-top: 8px;padding-bottom: 8px;line-height: 26px;margin-top: 10px;margin-bottom: 10px;font-size: 14px;word-spacing: 2px;\">\u4e0a\u8fb9\u6211\u4eec\u5b9e\u73b0\u4e86\u4e00\u4e2a\u6587\u4ef6\u590d\u5236\u7684\u4f8b\u5b50\uff0c\u6211\u4eec\u53ea\u662f\u62f7\u8d1d\u6e90\u6587\u4ef6\uff0c\u6ca1\u6709\u6d89\u53ca\u5230\u91cc\u8fb9\u7684\u5185\u5bb9\u64cd\u4f5c\uff0c\u63a5\u4e0b\u6765\u5b66\u4e60\u4e00\u4e0b\u5b57\u7b26\u64cd\u4f5c<\/p>\n<h3 style=\"margin-top: 30px;margin-bottom: 15px;font-weight: bold;text-align: center;\"><span style=\"border-bottom-width: 2px;border-bottom-style: solid;border-bottom-color: rgb(216, 156, 246);\">\u7f16\u7801\u4e0e\u89e3\u7801<\/span><\/h3>\n<p style=\"padding-top: 8px;padding-bottom: 8px;line-height: 26px;margin-top: 10px;margin-bottom: 10px;font-size: 14px;word-spacing: 2px;\">::: tip \u7f16\u7801\u5c31\u662f\u628a\u5b57\u7b26\u8f6c\u6362\u4e3a\u5b57\u8282\uff0c\u800c\u89e3\u7801\u662f\u628a\u5b57\u8282\u91cd\u65b0\u7ec4\u5408\u6210\u5b57\u7b26\u3002:::<\/p>\n<p style=\"padding-top: 8px;padding-bottom: 8px;line-height: 26px;margin-top: 10px;margin-bottom: 10px;font-size: 14px;word-spacing: 2px;\">\u901a\u5e38\u5462\uff0c\u6211\u4eec\u5bf9\u6587\u4ef6\u8fdb\u884c\u7f16\u7801\u548c\u89e3\u7801\u7684\u65f6\u5019\u4f7f\u7528\u7684\u662f\u540c\u4e00\u79cd\u683c\u5f0f\uff0c\u4e0d\u7136\u5c31\u4f1a\u51fa\u73b0\u4e71\u7801\uff0c\u6709\u65f6\u5019\u4f60\u6253\u5f00\u4e00\u4e2a\u6587\u4ef6\u5462\u51fa\u73b0\u4e00\u5806\u770b\u4e0d\u61c2\u7684\u5b57\u7b26\uff0c\u5f88\u6709\u53ef\u80fd\u662f\u4f60\u7684\u5de5\u5177\u4f7f\u7528\u4e86\u9519\u8bef\u7684\u7f16\u7801\u683c\u5f0f\u3002<\/p>\n<p style=\"padding-top: 8px;padding-bottom: 8px;line-height: 26px;margin-top: 10px;margin-bottom: 10px;font-size: 14px;word-spacing: 2px;\">\u8ba4\u8bc6\u4e00\u4e0b\u5e38\u89c1\u7684\u7f16\u7801\u683c\u5f0f:<\/p>\n<ul style=\"margin-top: 8px;margin-bottom: 8px;padding-left: 25px;font-size: 15px;list-style-type: circle;\" class=\"list-paddingleft-2\">\n<li>\n<section style=\"margin-top: 5px;margin-bottom: 5px;line-height: 26px;color: rgb(1, 1, 1);font-size: 14px;\"><strong style=\"color: rgb(145, 109, 213);\">\u300c<span style=\"color:#3eaf7c;\">GBK<\/span>\u300d<\/strong>&nbsp;\u7f16\u7801\u4e2d\uff0c\u4e2d\u6587\u5b57\u7b26\u5360 2 \u4e2a\u5b57\u8282\uff0c\u82f1\u6587\u5b57\u7b26\u5360 1 \u4e2a\u5b57\u8282\uff1b<\/section>\n<\/li>\n<li>\n<section style=\"margin-top: 5px;margin-bottom: 5px;line-height: 26px;color: rgb(1, 1, 1);font-size: 14px;\"><strong style=\"color: rgb(145, 109, 213);\">\u300c<span style=\"color:#3eaf7c;\">UTF-8<\/span>\u300d<\/strong>&nbsp;\u7f16\u7801\u4e2d\uff0c\u4e2d\u6587\u5b57\u7b26\u5360 3 \u4e2a\u5b57\u8282\uff0c\u82f1\u6587\u5b57\u7b26\u5360 1 \u4e2a\u5b57\u8282\uff1b<\/section>\n<\/li>\n<li>\n<section style=\"margin-top: 5px;margin-bottom: 5px;line-height: 26px;color: rgb(1, 1, 1);font-size: 14px;\"><strong style=\"color: rgb(145, 109, 213);\">\u300c<span style=\"color:#3eaf7c;\">UTF-16be<\/span>\u300d<\/strong>&nbsp;\u7f16\u7801\u4e2d\uff0c\u4e2d\u6587\u5b57\u7b26\u548c\u82f1\u6587\u5b57\u7b26\u90fd\u5360 2 \u4e2a\u5b57\u8282\u3002<\/section>\n<\/li>\n<\/ul>\n<p style=\"padding-top: 8px;padding-bottom: 8px;line-height: 26px;margin-top: 10px;margin-bottom: 10px;font-size: 14px;word-spacing: 2px;\">::: tip char \u7c7b\u578b\u5360 16 \u4f4d\uff0c\u4e5f\u5c31\u662f\u4e24\u4e2a\u5b57\u8282\uff0cJava \u4f7f\u7528\u8fd9\u79cd\u53cc\u5b57\u8282\u7f16\u7801\u662f\u4e3a\u4e86\u8ba9\u4e00\u4e2a\u4e2d\u6587\u6216\u8005\u4e00\u4e2a\u82f1\u6587\u90fd\u80fd\u4f7f\u7528\u4e00\u4e2a char \u6765\u5b58\u50a8 :::<\/p>\n<pre style=\"margin-top: 10px;margin-bottom: 10px;border-top-left-radius: 5px;border-top-right-radius: 5px;border-bottom-right-radius: 5px;border-bottom-left-radius: 5px;box-shadow: rgba(0, 0, 0, 0.55) 0px 2px 10px;\"><span style=\"display: block;background-image: url('https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2023\/05\/20230528042704988.jpeg');height: 30px;width: 749px;background-size: 40px;background-color: rgb(40, 44, 52);margin-bottom: -7px;border-top-left-radius: 5px;border-top-right-radius: 5px;border-bottom-right-radius: 5px;border-bottom-left-radius: 5px;background-position: 10px 10px;background-repeat: no-repeat no-repeat;\"><\/span><code style=\"overflow-x: auto;padding: 15px 16px 16px;color: rgb(171, 178, 191);display: -webkit-box;font-family: &quot;Operator Mono&quot;, Consolas, Monaco, Menlo, monospace;font-size: 12px;background-color: rgb(40, 44, 52);border-top-left-radius: 5px;border-top-right-radius: 5px;border-bottom-right-radius: 5px;border-bottom-left-radius: 5px;\"><span style=\"line-height: 26px;\"><span style=\"color: rgb(198, 120, 221);line-height: 26px;\">public<\/span>&nbsp;<span style=\"color: rgb(198, 120, 221);line-height: 26px;\">static<\/span>&nbsp;<span style=\"color: rgb(198, 120, 221);line-height: 26px;\">void<\/span>&nbsp;<span style=\"color: rgb(97, 174, 238);line-height: 26px;\">stringCodec<\/span><span style=\"line-height: 26px;\">()<\/span>&nbsp;<span style=\"color: rgb(198, 120, 221);line-height: 26px;\">throws<\/span>&nbsp;UnsupportedEncodingException&nbsp;<\/span>{<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;String&nbsp;hello&nbsp;=&nbsp;<span style=\"color: rgb(152, 195, 121);line-height: 26px;\">\"Hello\"<\/span>;<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"color: rgb(92, 99, 112);font-style: italic;line-height: 26px;\">\/\/&nbsp;\u7f16\u7801&nbsp;UTF-8<\/span><br  \/>&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"color: rgb(198, 120, 221);line-height: 26px;\">byte<\/span>[]&nbsp;bytes&nbsp;=&nbsp;hello.getBytes(<span style=\"color: rgb(152, 195, 121);line-height: 26px;\">\"UTF-8\"<\/span>);<br  \/><br  \/>&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"color: rgb(92, 99, 112);font-style: italic;line-height: 26px;\">\/\/&nbsp;\u89e3\u7801&nbsp;UTF-8<\/span><br  \/>&nbsp;&nbsp;&nbsp;&nbsp;String&nbsp;hello1&nbsp;=&nbsp;<span style=\"color: rgb(198, 120, 221);line-height: 26px;\">new<\/span>&nbsp;String(bytes,&nbsp;<span style=\"color: rgb(152, 195, 121);line-height: 26px;\">\"UTF-8\"<\/span>);<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;Log.info(hello1);&nbsp;<span style=\"color: rgb(92, 99, 112);font-style: italic;line-height: 26px;\">\/\/&nbsp;Hello<\/span><br  \/>}<br  \/><\/code><\/pre>\n<p style=\"padding-top: 8px;padding-bottom: 8px;line-height: 26px;margin-top: 10px;margin-bottom: 10px;font-size: 14px;word-spacing: 2px;\">\u5728\u8c03\u7528\u65e0\u53c2\u6570&nbsp;&nbsp;<strong style=\"color: rgb(145, 109, 213);\">\u300c<span style=\"color:#3eaf7c;\">getBytes()<\/span>\u300d<\/strong>&nbsp;\u65b9\u6cd5\u65f6\uff0c\u9ed8\u8ba4\u7684\u7f16\u7801\u65b9\u5f0f\u4e0d\u662f <span style=\"color:#3eaf7c;\">UTF-16be<\/span>\u3002\u53cc\u5b57\u8282\u7f16\u7801\u7684\u597d\u5904\u662f\u53ef\u4ee5\u4f7f\u7528\u4e00\u4e2a&nbsp;&nbsp;<strong style=\"color: rgb(145, 109, 213);\">\u300c<span style=\"color:#3eaf7c;\">char<\/span>\u300d<\/strong>&nbsp;\u5b58\u50a8\u4e2d\u6587\u548c\u82f1\u6587\uff0c\u800c\u5c06&nbsp;&nbsp;<strong style=\"color: rgb(145, 109, 213);\">\u300c<span style=\"color:#3eaf7c;\">String<\/span>\u300d<\/strong>&nbsp;\u8f6c\u4e3a&nbsp;&nbsp;<strong style=\"color: rgb(145, 109, 213);\">\u300c<span style=\"color:#3eaf7c;\">bytes[]<\/span>\u300d<\/strong>&nbsp;\u5b57\u8282\u6570\u7ec4\u5c31\u4e0d\u518d\u9700\u8981\u8fd9\u4e2a\u597d\u5904\uff0c\u56e0\u6b64\u4e5f\u5c31\u4e0d\u518d\u9700\u8981\u53cc\u5b57\u8282\u7f16\u7801\u3002&nbsp;<strong style=\"color: rgb(145, 109, 213);\">\u300c<span style=\"color:#3eaf7c;\">getBytes()<\/span>\u300d<\/strong>&nbsp;\u7684\u9ed8\u8ba4\u7f16\u7801\u65b9\u5f0f\u4e0e\u5e73\u53f0\u6709\u5173\uff0c\u4e00\u822c\u4e3a <span style=\"color:#3eaf7c;\">UTF-8<\/span>\u3002<\/p>\n<h3 style=\"margin-top: 30px;margin-bottom: 15px;font-weight: bold;text-align: center;\"><span style=\"border-bottom-width: 2px;border-bottom-style: solid;border-bottom-color: rgb(216, 156, 246);\">\u6587\u4ef6\u5185\u5bb9\u64cd\u4f5c InputStreamReader &amp; OutputStreamWriter<\/span><\/h3>\n<p style=\"padding-top: 8px;padding-bottom: 8px;line-height: 26px;margin-top: 10px;margin-bottom: 10px;font-size: 14px;word-spacing: 2px;\">\u4e0d\u7ba1\u662f\u78c1\u76d8\u8fd8\u662f\u7f51\u7edc\u4f20\u8f93\uff0c\u6700\u5c0f\u7684\u5b58\u50a8\u5355\u5143\u90fd\u662f\u5b57\u8282\uff0c\u800c\u4e0d\u662f\u5b57\u7b26\u3002\u4f46\u662f\u5728\u7a0b\u5e8f\u4e2d\u64cd\u4f5c\u7684\u901a\u5e38\u662f\u5b57\u7b26\u5f62\u5f0f\u7684\u6570\u636e\uff0c\u56e0\u6b64\u9700\u8981\u63d0\u4f9b\u5bf9\u5b57\u7b26\u8fdb\u884c\u64cd\u4f5c\u7684\u65b9\u6cd5\u3002\u6d89\u53ca\u4e24\u4e2a\u7c7b:<\/p>\n<ul style=\"margin-top: 8px;margin-bottom: 8px;padding-left: 25px;font-size: 15px;list-style-type: circle;\" class=\"list-paddingleft-2\">\n<li>\n<section style=\"margin-top: 5px;margin-bottom: 5px;line-height: 26px;color: rgb(1, 1, 1);font-size: 14px;\">\n<p style=\"padding-top: 8px;padding-bottom: 8px;line-height: 26px;color: black;margin-top: 10px;margin-bottom: 10px;word-spacing: 2px;\">InputStreamReader \u5b9e\u73b0\u4ece\u5b57\u8282\u6d41\u89e3\u7801\u6210\u5b57\u7b26\u6d41\uff1b<\/p>\n<\/section>\n<\/li>\n<li>\n<section style=\"margin-top: 5px;margin-bottom: 5px;line-height: 26px;color: rgb(1, 1, 1);font-size: 14px;\">\n<p style=\"padding-top: 8px;padding-bottom: 8px;line-height: 26px;color: black;margin-top: 10px;margin-bottom: 10px;word-spacing: 2px;\">OutputStreamWriter \u5b9e\u73b0\u5b57\u7b26\u6d41\u7f16\u7801\u6210\u4e3a\u5b57\u8282\u6d41\u3002<\/p>\n<\/section>\n<\/li>\n<\/ul>\n<p style=\"padding-top: 8px;padding-bottom: 8px;line-height: 26px;margin-top: 10px;margin-bottom: 10px;font-size: 14px;word-spacing: 2px;\">\u6765\u770b\u4e00\u4e0b\u5b9e\u64cd\u4ee3\u7801\uff1a<\/p>\n<pre style=\"margin-top: 10px;margin-bottom: 10px;border-top-left-radius: 5px;border-top-right-radius: 5px;border-bottom-right-radius: 5px;border-bottom-left-radius: 5px;box-shadow: rgba(0, 0, 0, 0.55) 0px 2px 10px;\"><span style=\"display: block;background-image: url('https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2023\/05\/20230528042704988.jpeg');height: 30px;width: 749px;background-size: 40px;background-color: rgb(40, 44, 52);margin-bottom: -7px;border-top-left-radius: 5px;border-top-right-radius: 5px;border-bottom-right-radius: 5px;border-bottom-left-radius: 5px;background-position: 10px 10px;background-repeat: no-repeat no-repeat;\"><\/span><code style=\"overflow-x: auto;padding: 15px 16px 16px;color: rgb(171, 178, 191);display: -webkit-box;font-family: &quot;Operator Mono&quot;, Consolas, Monaco, Menlo, monospace;font-size: 12px;background-color: rgb(40, 44, 52);border-top-left-radius: 5px;border-top-right-radius: 5px;border-bottom-right-radius: 5px;border-bottom-left-radius: 5px;\">&nbsp;<span style=\"line-height: 26px;\"><span style=\"color: rgb(198, 120, 221);line-height: 26px;\">public<\/span>&nbsp;<span style=\"color: rgb(198, 120, 221);line-height: 26px;\">static<\/span>&nbsp;<span style=\"color: rgb(198, 120, 221);line-height: 26px;\">void<\/span>&nbsp;<span style=\"color: rgb(97, 174, 238);line-height: 26px;\">readContent<\/span><span style=\"line-height: 26px;\">(String&nbsp;src)<\/span>&nbsp;<span style=\"color: rgb(198, 120, 221);line-height: 26px;\">throws<\/span>&nbsp;IOException&nbsp;<\/span>{<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;FileReader&nbsp;reader&nbsp;=&nbsp;<span style=\"color: rgb(198, 120, 221);line-height: 26px;\">new<\/span>&nbsp;FileReader(src);<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"color: rgb(92, 99, 112);font-style: italic;line-height: 26px;\">\/\/&nbsp;\u88c5\u9970\u5668\uff08\u7f13\u51b2\u533a\uff09<\/span><br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;BufferedReader&nbsp;reader2&nbsp;=&nbsp;<span style=\"color: rgb(198, 120, 221);line-height: 26px;\">new<\/span>&nbsp;BufferedReader(reader);<br  \/><br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;String&nbsp;line;<br  \/><br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"color: rgb(92, 99, 112);font-style: italic;line-height: 26px;\">\/\/&nbsp;\u9010\u884c\u8bfb\u53d6<\/span><br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"color: rgb(198, 120, 221);line-height: 26px;\">while<\/span>&nbsp;((line&nbsp;=&nbsp;reader2.readLine())&nbsp;!=&nbsp;<span style=\"color: rgb(198, 120, 221);line-height: 26px;\">null<\/span>)&nbsp;{<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Log.info(line);<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br  \/><br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;reader2.close();<br  \/><br  \/><br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"color: rgb(92, 99, 112);font-style: italic;line-height: 26px;\">\/\/&nbsp;writer\u5b9e\u73b0&nbsp;\u5b57\u7b26\u8f6c\u4e3a\u5b57\u8282\u5199\u5165\u5230\u76ee\u6807\u6587\u4ef6<\/span><br  \/><br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"color: rgb(92, 99, 112);font-style: italic;line-height: 26px;\">\/\/&nbsp;\u521b\u5efa\u4e00\u4e2a\u8f93\u51fa\u6d41<\/span><br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;FileOutputStream&nbsp;output&nbsp;=&nbsp;<span style=\"color: rgb(198, 120, 221);line-height: 26px;\">new<\/span>&nbsp;FileOutputStream(src);<br  \/><br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"color: rgb(92, 99, 112);font-style: italic;line-height: 26px;\">\/\/&nbsp;\u521b\u5efa\u4e00\u4e2a\u5199\u5165\u6d41&nbsp;-&gt;&nbsp;\u5199\u5165\u5230\u8f93\u51fa\u6d41,\u76ee\u6807\u6587\u4ef6\u4e2d<\/span><br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;OutputStreamWriter&nbsp;writer&nbsp;=&nbsp;<span style=\"color: rgb(198, 120, 221);line-height: 26px;\">new<\/span>&nbsp;OutputStreamWriter(output);<br  \/><br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"color: rgb(92, 99, 112);font-style: italic;line-height: 26px;\">\/\/&nbsp;\u5199\u5165\u7684\u6570\u636e<\/span><br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;String&nbsp;data&nbsp;=&nbsp;<span style=\"color: rgb(152, 195, 121);line-height: 26px;\">\"\u8fd9\u662f\u6211\u8ffd\u52a0\u7684\u6570\u636e\"<\/span>;<br  \/><br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"color: rgb(92, 99, 112);font-style: italic;line-height: 26px;\">\/\/&nbsp;write\u4f1a\u5bfc\u81f4\u5168\u90e8\u91cd\u5199&nbsp;(\u5982\u679c\u662f\u5199\u5165\u65b0\u6587\u4ef6\u53ef\u4ee5\u8fd9\u4e48\u5199)<\/span><br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;writer.write(data);<br  \/><br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"color: rgb(92, 99, 112);font-style: italic;line-height: 26px;\">\/\/&nbsp;\u5f3a\u5236\u5c06\u5199\u5165\u5668\u4e2d\u5b58\u5728\u7684\u6240\u6709\u6570\u636e\u5199\u5165\u76f8\u5e94\u7684\u76ee\u7684\u5730<\/span><br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"color: rgb(92, 99, 112);font-style: italic;line-height: 26px;\">\/\/&nbsp;writer.flush();<\/span><br  \/><br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"color: rgb(92, 99, 112);font-style: italic;line-height: 26px;\">\/\/&nbsp;\u5c06\u6307\u5b9a\u5b57\u7b26\u63d2\u5165\u5f53\u524d\u7f16\u5199\u5668&nbsp;\u5728\u5c3e\u90e8\u6dfb\u52a0<\/span><br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;writer.append(<span style=\"color: rgb(152, 195, 121);line-height: 26px;\">\"n\"<\/span>&nbsp;+&nbsp;data);<br  \/><br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"color: rgb(92, 99, 112);font-style: italic;line-height: 26px;\">\/\/&nbsp;\u5148\u5173\u95ed\u5199\u5165\u6d41<\/span><br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;writer.close();<br  \/><br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"color: rgb(92, 99, 112);font-style: italic;line-height: 26px;\">\/\/&nbsp;\u540e\u5173\u95ed\u8f93\u51fa\u6d41<\/span><br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;output.close();<br  \/>&nbsp;&nbsp;}<br  \/><\/code><\/pre>\n<h2 style=\"font-weight: bold;font-size: 22px;margin-top: 20px;margin-right: 10px;\"><span style=\"font-size: 18px;display: inline-block;padding-left: 10px;border-left-width: 5px;border-left-style: solid;border-left-color: rgb(145, 109, 213);\">\u5bf9\u8c61\u64cd\u4f5c Serializable &amp; Externalizable<\/span><\/h2>\n<p style=\"padding-top: 8px;padding-bottom: 8px;line-height: 26px;margin-top: 10px;margin-bottom: 10px;font-size: 14px;word-spacing: 2px;\">\u4e0b\u8fb9\u7684\u5185\u5bb9\u5c06\u4f1a\u9010\u6e10\u52a0\u6df1\uff0c\u6d89\u53ca\u7684\u77e5\u8bc6\u70b9\u4e5f\u662f\u6bd4\u8f83\u6838\u5fc3\u7684\uff0c\u8981\u8010\u5fc3\u770b\u5b8c\u54e6 ~<\/p>\n<p style=\"padding-top: 8px;padding-bottom: 8px;line-height: 26px;margin-top: 10px;margin-bottom: 10px;font-size: 14px;word-spacing: 2px;\">\u8bf4\u5230&nbsp;&nbsp;<strong style=\"color: rgb(145, 109, 213);\">\u300c<span style=\"color:#3eaf7c;\">Serializable<\/span>\u300d<\/strong>&nbsp;\uff0c\u6211\u4eec\u5de5\u4f5c\u4e2d\u7ecf\u5e38\u4f1a\u770b\u5230\u540c\u4e8b\u7684\u4ee3\u7801\uff0c\u5b9e\u4f53\u7c7b&nbsp;<code style=\"word-wrap: break-word;padding: 2px 4px;border-top-left-radius: 4px;border-top-right-radius: 4px;border-bottom-right-radius: 4px;border-bottom-left-radius: 4px;margin-right: 2px;margin-left: 2px;font-family: &quot;Operator Mono&quot;, Consolas, Monaco, Menlo, monospace;word-break: break-all;color: rgb(145, 109, 213);background-image: none;\">implements Serializable<\/code>&nbsp;\u52a0\u4e0a\u4e86\u8fd9\u4e48\u4e2a\u4e1c\u4e1c\uff0c \u7b2c\u4e00\u5370\u8c61\u80af\u5b9a\u8054\u60f3\u5230\u662f&nbsp;<strong style=\"color: rgb(145, 109, 213);\">\u300c<span style=\"color:#3eaf7c;\">\u5bf9\u8c61\u5e8f\u5217\u5316<\/span>\u300d<\/strong>&nbsp;,\u90a3\u4f60\u77e5\u9053\u4e3a\u4ec0\u4e48\u8981\u8fd9\u6837\u505a\u5417\uff1f<\/p>\n<h3 style=\"margin-top: 30px;margin-bottom: 15px;font-weight: bold;text-align: center;\"><span style=\"border-bottom-width: 2px;border-bottom-style: solid;border-bottom-color: rgb(216, 156, 246);\">\u5e8f\u5217\u5316 &amp; \u53cd\u5e8f\u5217\u5316<\/span><\/h3>\n<p style=\"padding-top: 8px;padding-bottom: 8px;line-height: 26px;margin-top: 10px;margin-bottom: 10px;font-size: 14px;word-spacing: 2px;\">\u5728\u8bb2\u89e3\u4e4b\u524d\uff0c\u6211\u4eec\u8fd8\u662f\u5148\u53bb\u7406\u89e3\u8fd9\u4e24\u4e2a\u6982\u5ff5\u6027\u7684\u4e1c\u897f~<\/p>\n<ul style=\"margin-top: 8px;margin-bottom: 8px;padding-left: 25px;font-size: 15px;list-style-type: circle;\" class=\"list-paddingleft-2\">\n<li>\n<section style=\"margin-top: 5px;margin-bottom: 5px;line-height: 26px;color: rgb(1, 1, 1);font-size: 14px;\"><strong style=\"color: rgb(145, 109, 213);\">\u300c<span style=\"color:#3eaf7c;\">\u5e8f\u5217\u5316<\/span>\u300d<\/strong>&nbsp;\u5b57\u9762\u610f\u601d,\u5c06\u5bf9\u8c61\u5b58\u8f6c\u4e3a\u5b57\u8282\u5e8f\u5217<\/section>\n<\/li>\n<li>\n<section style=\"margin-top: 5px;margin-bottom: 5px;line-height: 26px;color: rgb(1, 1, 1);font-size: 14px;\"><strong style=\"color: rgb(145, 109, 213);\">\u300c<span style=\"color:#3eaf7c;\">\u996d\u5e8f\u5217\u5316<\/span>\u300d<\/strong>&nbsp;\u5c06\u5b57\u8282\u5e8f\u5217\u8f6c\u4e3a\u539f\u6765\u7684\u6807\u51c6\u5bf9\u8c61<\/section>\n<\/li>\n<\/ul>\n<p style=\"padding-top: 8px;padding-bottom: 8px;line-height: 26px;margin-top: 10px;margin-bottom: 10px;font-size: 14px;word-spacing: 2px;\">\u4e3a\u4ec0\u4e48\u8981\u8fdb\u884c\u5bf9\u8c61\u5e8f\u5217\u5316\uff1f<\/p>\n<p style=\"padding-top: 8px;padding-bottom: 8px;line-height: 26px;margin-top: 10px;margin-bottom: 10px;font-size: 14px;word-spacing: 2px;\">\u5982\u679c\u4f60\u6709\u8fd9\u6837\u7684\u9700\u6c42\uff0c\u56e0\u4e3a\u7a0b\u5e8f\u4e00\u5173\u95ed\u6570\u636e\u5c31\u4f1a\u4ece\u5185\u5b58\u4e2d\u6d88\u5931, \u73b0\u5728\u9700\u8981\u628a\u5bf9\u8c61\u5b58\u50a8\u5230\u78c1\u76d8\u4e2d\uff0c\u90a3\u4f60\u5c31\u9700\u8981\u8fdb\u884c\u5e8f\u5217\u5316\u64cd\u4f5c\uff0c\u56e0\u4e3a\u6587\u4ef6\u64cd\u4f5c\u6d89\u53ca\u5230\u5b57\u8282\u64cd\u4f5c\u3002\u518d\u6216\u8005\u4f60\u8981\u628a\u5bf9\u8c61\u8fdb\u884c\u4f20\u8f93\u5230\u5176\u5b83\u7684\u5730\u65b9\u6267\u884c\uff0c\u901a\u5e38\u662f\u901a\u8fc7\u7f51\u7edc\u4f20\u8f93\uff0c\u8fd9\u4e5f\u5f15\u7533\u4e86\u4e00\u4e2a\u5c0f\u77e5\u8bc6\u70b9&nbsp;<strong style=\"color: rgb(145, 109, 213);\">\u300c<span style=\"color:#3eaf7c;\">rpc<\/span>\u300d<\/strong>&nbsp;\u8fdc\u7a0b\u8c03\u7528\uff0c\u5982\u679c\u4f60\u505a\u8fc7\u5fae\u670d\u52a1\u80af\u5b9a\u4e5f\u4e0d\u964c\u751f\u4e86\uff0c\u8fd9\u91cc\u4e0d\u5c55\u5f00\u8bb2\u4e86\uff0c\u540e\u8fb9\u4f1a\u6709\u4e13\u95e8\u6587\u7ae0\u8bf4\u4e00\u4e0b\u8fd9\u4e2a\u5b9e\u73b0\u3002<\/p>\n<p style=\"padding-top: 8px;padding-bottom: 8px;line-height: 26px;margin-top: 10px;margin-bottom: 10px;font-size: 14px;word-spacing: 2px;\">\u5728Java\u4e2d\u5b9e\u73b0\u5e8f\u5217\u5316\u4e3b\u8981\u901a\u8fc7\u4e24\u4e2a\u63a5\u53e3:<\/p>\n<ul style=\"margin-top: 8px;margin-bottom: 8px;padding-left: 25px;font-size: 15px;list-style-type: circle;\" class=\"list-paddingleft-2\">\n<li>\n<section style=\"margin-top: 5px;margin-bottom: 5px;line-height: 26px;color: rgb(1, 1, 1);font-size: 14px;\">Serializable \u63a5\u53e3<\/section>\n<\/li>\n<li>\n<section style=\"margin-top: 5px;margin-bottom: 5px;line-height: 26px;color: rgb(1, 1, 1);font-size: 14px;\">Externalizable \u63a5\u53e3<\/section>\n<\/li>\n<\/ul>\n<h3 style=\"margin-top: 30px;margin-bottom: 15px;font-weight: bold;text-align: center;\"><span style=\"border-bottom-width: 2px;border-bottom-style: solid;border-bottom-color: rgb(216, 156, 246);\">Serializable<\/span><\/h3>\n<p style=\"padding-top: 8px;padding-bottom: 8px;line-height: 26px;margin-top: 10px;margin-bottom: 10px;font-size: 14px;word-spacing: 2px;\">\u4e00\u4e2a\u5bf9\u8c61\u60f3\u8981\u88ab\u5e8f\u5217\u5316\uff0c\u90a3\u4e48\u5b83\u7684\u7c7b\u5c31\u8981\u5b9e\u73b0\u6b64\u63a5\u53e3\u6216\u8005\u5b83\u7684\u5b50\u63a5\u53e3\u3002\u8fd9\u4e2a\u5bf9\u8c61\u7684\u6240\u6709\u5c5e\u6027\uff08\u5305\u62ecprivate\u5c5e\u6027\u3001\u5305\u62ec\u5176\u5f15\u7528\u7684\u5bf9\u8c61\uff09\u90fd\u53ef\u4ee5\u88ab\u5e8f\u5217\u5316\u548c\u53cd\u5e8f\u5217\u5316\u6765\u4fdd\u5b58\u3001\u4f20\u9012\u3002\u4e0d\u60f3\u5e8f\u5217\u5316\u7684\u5b57\u6bb5\u53ef\u4ee5\u4f7f\u7528transient\u4fee\u9970\u3002\u7531\u4e8eSerializable\u5bf9\u8c61\u5b8c\u5168\u4ee5\u5b83\u5b58\u50a8\u7684\u4e8c\u8fdb\u5236\u4f4d\u4e3a\u57fa\u7840\u6765\u6784\u9020\uff0c\u56e0\u6b64\u5e76\u4e0d\u4f1a\u8c03\u7528\u4efb\u4f55\u6784\u9020\u51fd\u6570\uff0c\u56e0\u6b64Serializable\u7c7b\u65e0\u9700\u9ed8\u8ba4\u6784\u9020\u51fd\u6570\uff0c\u4f46\u662f\u5f53Serializable\u7c7b\u7684\u7236\u7c7b\u6ca1\u6709\u5b9e\u73b0Serializable\u63a5\u53e3\u65f6\uff0c\u53cd\u5e8f\u5217\u5316\u8fc7\u7a0b\u4f1a\u8c03\u7528\u7236\u7c7b\u7684\u9ed8\u8ba4\u6784\u9020\u51fd\u6570\uff0c\u56e0\u6b64\u8be5\u7236\u7c7b\u5fc5\u9700\u6709\u9ed8\u8ba4\u6784\u9020\u51fd\u6570\uff0c\u5426\u5219\u4f1a\u629b\u5f02\u5e38\u3002\u4f7f\u7528transient\u5173\u952e\u5b57\u963b\u6b62\u5e8f\u5217\u5316\u867d\u7136\u7b80\u5355\u65b9\u4fbf\uff0c\u4f46\u88ab\u5b83\u4fee\u9970\u7684\u5c5e\u6027\u88ab\u5b8c\u5168\u9694\u79bb\u5728\u5e8f\u5217\u5316\u673a\u5236\u4e4b\u5916\uff0c\u5bfc\u81f4\u4e86\u5728\u53cd\u5e8f\u5217\u5316\u65f6\u65e0\u6cd5\u83b7\u53d6\u8be5\u5c5e\u6027\u7684\u503c\uff0c\u800c\u901a\u8fc7\u5728\u9700\u8981\u5e8f\u5217\u5316\u7684\u5bf9\u8c61\u7684Java\u7c7b\u91cc\u52a0\u5165writeObject()\u65b9\u6cd5\u4e0ereadObject()\u65b9\u6cd5\u53ef\u4ee5\u63a7\u5236\u5982\u4f55\u5e8f\u5217\u5316\u5404\u5c5e\u6027\uff0c\u751a\u81f3\u5b8c\u5168\u4e0d\u5e8f\u5217\u5316\u67d0\u4e9b\u5c5e\u6027\u6216\u8005\u52a0\u5bc6\u5e8f\u5217\u5316\u67d0\u4e9b\u5c5e\u6027\u3002<\/p>\n<h3 style=\"margin-top: 30px;margin-bottom: 15px;font-weight: bold;text-align: center;\"><span style=\"border-bottom-width: 2px;border-bottom-style: solid;border-bottom-color: rgb(216, 156, 246);\">Externalizable<\/span><\/h3>\n<p style=\"padding-top: 8px;padding-bottom: 8px;line-height: 26px;margin-top: 10px;margin-bottom: 10px;font-size: 14px;word-spacing: 2px;\">\u5b83\u662fSerializable\u63a5\u53e3\u7684\u5b50\u7c7b\uff0c\u7528\u6237\u8981\u5b9e\u73b0\u7684writeExternal()\u548creadExternal() \u65b9\u6cd5\uff0c\u7528\u6765\u51b3\u5b9a\u5982\u4f55\u5e8f\u5217\u5316\u548c\u53cd\u5e8f\u5217\u5316\u3002\u56e0\u4e3a\u5e8f\u5217\u5316\u548c\u53cd\u5e8f\u5217\u5316\u65b9\u6cd5\u9700\u8981\u81ea\u5df1\u5b9e\u73b0\uff0c\u56e0\u6b64\u53ef\u4ee5\u6307\u5b9a\u5e8f\u5217\u5316\u54ea\u4e9b\u5c5e\u6027\uff0c\u800ctransient\u5728\u8fd9\u91cc\u65e0\u6548\u3002\u5bf9Externalizable\u5bf9\u8c61\u53cd\u5e8f\u5217\u5316\u65f6\uff0c\u4f1a\u5148\u8c03\u7528\u7c7b\u7684\u65e0\u53c2\u6784\u9020\u65b9\u6cd5\uff0c\u8fd9\u662f\u6709\u522b\u4e8e\u9ed8\u8ba4\u53cd\u5e8f\u5217\u65b9\u5f0f\u7684\u3002\u5982\u679c\u628a\u7c7b\u7684\u4e0d\u5e26\u53c2\u6570\u7684\u6784\u9020\u65b9\u6cd5\u5220\u9664\uff0c\u6216\u8005\u628a\u8be5\u6784\u9020\u65b9\u6cd5\u7684\u8bbf\u95ee\u6743\u9650\u8bbe\u7f6e\u4e3aprivate\u3001\u9ed8\u8ba4\u6216protected\u7ea7\u522b\uff0c\u4f1a\u629b\u51fajava.io.InvalidException: no valid constructor\u5f02\u5e38\uff0c\u56e0\u6b64Externalizable\u5bf9\u8c61\u5fc5\u987b\u6709\u9ed8\u8ba4\u6784\u9020\u51fd\u6570\uff0c\u800c\u4e14\u5fc5\u9700\u662fpublic\u7684\u3002<\/p>\n<h3 style=\"margin-top: 30px;margin-bottom: 15px;font-weight: bold;text-align: center;\"><span style=\"border-bottom-width: 2px;border-bottom-style: solid;border-bottom-color: rgb(216, 156, 246);\">\u52a8\u624b\u5b9e\u73b0<\/span><\/h3>\n<p style=\"padding-top: 8px;padding-bottom: 8px;line-height: 26px;margin-top: 10px;margin-bottom: 10px;font-size: 14px;word-spacing: 2px;\">\u597d\uff0c\u6709\u4e86\u4ee5\u4e0a\u57fa\u7840\u77e5\u8bc6\u7684\u94fa\u57ab\uff0c\u4e0b\u9762\u6211\u4eec\u901a\u8fc7\u4f8b\u5b50\u6765\u76f4\u89c2\u611f\u53d7\u4e00\u4e0b:<\/p>\n<p style=\"padding-top: 8px;padding-bottom: 8px;line-height: 26px;margin-top: 10px;margin-bottom: 10px;font-size: 14px;word-spacing: 2px;\">\u5148\u5b9a\u4e49\u4e00\u4e2a\u7c7b\uff1a<\/p>\n<pre style=\"margin-top: 10px;margin-bottom: 10px;border-top-left-radius: 5px;border-top-right-radius: 5px;border-bottom-right-radius: 5px;border-bottom-left-radius: 5px;box-shadow: rgba(0, 0, 0, 0.55) 0px 2px 10px;\"><span style=\"display: block;background-image: url('https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2023\/05\/20230528042704988.jpeg');height: 30px;width: 749px;background-size: 40px;background-color: rgb(40, 44, 52);margin-bottom: -7px;border-top-left-radius: 5px;border-top-right-radius: 5px;border-bottom-right-radius: 5px;border-bottom-left-radius: 5px;background-position: 10px 10px;background-repeat: no-repeat no-repeat;\"><\/span><code style=\"overflow-x: auto;padding: 15px 16px 16px;color: rgb(171, 178, 191);display: -webkit-box;font-family: &quot;Operator Mono&quot;, Consolas, Monaco, Menlo, monospace;font-size: 12px;background-color: rgb(40, 44, 52);border-top-left-radius: 5px;border-top-right-radius: 5px;border-bottom-right-radius: 5px;border-bottom-left-radius: 5px;\"><span style=\"line-height: 26px;\"><span style=\"color: rgb(198, 120, 221);line-height: 26px;\">class<\/span>&nbsp;<span style=\"color: rgb(230, 192, 123);line-height: 26px;\">Apple<\/span>&nbsp;<span style=\"color: rgb(198, 120, 221);line-height: 26px;\">implements<\/span>&nbsp;<span style=\"color: rgb(230, 192, 123);line-height: 26px;\">Serializable<\/span>&nbsp;<\/span>{<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"color: rgb(92, 99, 112);font-style: italic;line-height: 26px;\">\/**<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;* serialVersionUID \u662f\u5b9e\u73b0 Serializable \u63a5\u53e3\u800c\u6765\u7684\uff0c\u800c Serializable \u5219\u662f\u5e94\u7528\u4e8eJava \u5bf9\u8c61\u5e8f\u5217\u5316\/\u53cd\u5e8f\u5217\u5316\u3002<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;\u5bf9\u8c61\u7684\u5e8f\u5217\u5316\u4e3b\u8981\u6709\u4e24\u79cd\u7528\u9014:<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;1.&nbsp;\u628a\u5bf9\u8c61\u5e8f\u5217\u5316\u6210\u5b57\u8282\u7801\uff0c\u4fdd\u5b58\u5230\u6307\u5b9a\u4ecb\u8d28\u4e0a(\u5982\u78c1\u76d8\u7b49)<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;2.&nbsp;\u7528\u4e8e\u7f51\u7edc\u4f20\u8f93<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;* serialVersionUID \u662f Java \u4e3a\u6bcf\u4e2a\u5e8f\u5217\u5316\u7c7b\u4ea7\u751f\u7684\u7248\u672c\u6807\u8bc6\uff0c\u53ef\u7528\u6765\u4fdd\u8bc1\u5728\u53cd\u5e8f\u5217\u65f6\uff0c\u53d1\u9001\u65b9\u53d1\u9001\u7684\u548c\u63a5\u53d7\u65b9\u63a5\u6536\u7684\u662f\u53ef\u517c\u5bb9\u7684\u5bf9\u8c61\u3002<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;\u5982\u679c\u63a5\u6536\u65b9\u63a5\u6536\u7684\u7c7b\u7684&nbsp;serialVersionUID&nbsp;\u4e0e\u53d1\u9001\u65b9\u53d1\u9001\u7684&nbsp;serialVersionUID&nbsp;\u4e0d\u4e00\u81f4\uff0c\u8fdb\u884c\u53cd\u5e8f\u5217\u65f6\u4f1a\u629b\u51fa&nbsp;InvalidClassException<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*\/<\/span><br  \/>&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"color: rgb(198, 120, 221);line-height: 26px;\">private<\/span>&nbsp;<span style=\"color: rgb(198, 120, 221);line-height: 26px;\">static<\/span>&nbsp;<span style=\"color: rgb(198, 120, 221);line-height: 26px;\">final<\/span>&nbsp;<span style=\"color: rgb(198, 120, 221);line-height: 26px;\">long<\/span>&nbsp;serialVersionUID&nbsp;=&nbsp;<span style=\"color: rgb(209, 154, 102);line-height: 26px;\">1L<\/span>;<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"color: rgb(198, 120, 221);line-height: 26px;\">private<\/span>&nbsp;<span style=\"color: rgb(198, 120, 221);line-height: 26px;\">int<\/span>&nbsp;x;<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"color: rgb(198, 120, 221);line-height: 26px;\">private<\/span>&nbsp;String&nbsp;y;<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"color: rgb(198, 120, 221);line-height: 26px;\">transient<\/span>&nbsp;String&nbsp;z;<br  \/><br  \/>&nbsp;&nbsp;&nbsp;&nbsp;Apple(<span style=\"color: rgb(198, 120, 221);line-height: 26px;\">int<\/span>&nbsp;x,&nbsp;String&nbsp;y)&nbsp;{<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"color: rgb(198, 120, 221);line-height: 26px;\">this<\/span>.x&nbsp;=&nbsp;x;<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"color: rgb(198, 120, 221);line-height: 26px;\">this<\/span>.y&nbsp;=&nbsp;y;<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"color: rgb(198, 120, 221);line-height: 26px;\">this<\/span>.z&nbsp;=&nbsp;<span style=\"color: rgb(152, 195, 121);line-height: 26px;\">\"z\"<\/span>;<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;}<br  \/><br  \/>&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"color: rgb(97, 174, 238);line-height: 26px;\">@Override<\/span><br  \/>&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"line-height: 26px;\"><span style=\"color: rgb(198, 120, 221);line-height: 26px;\">public<\/span>&nbsp;String&nbsp;<span style=\"color: rgb(97, 174, 238);line-height: 26px;\">toString<\/span><span style=\"line-height: 26px;\">()<\/span>&nbsp;<\/span>{<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"color: rgb(198, 120, 221);line-height: 26px;\">return<\/span>&nbsp;<span style=\"color: rgb(152, 195, 121);line-height: 26px;\">\"x&nbsp;=&nbsp;\"<\/span>&nbsp;+&nbsp;x&nbsp;+&nbsp;<span style=\"color: rgb(152, 195, 121);line-height: 26px;\">\"&nbsp;&nbsp;\"<\/span>&nbsp;+&nbsp;<span style=\"color: rgb(152, 195, 121);line-height: 26px;\">\"y&nbsp;=&nbsp;\"<\/span>&nbsp;+&nbsp;y&nbsp;+&nbsp;<span style=\"color: rgb(152, 195, 121);line-height: 26px;\">\"&nbsp;&nbsp;\"<\/span>&nbsp;+z;<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;}<br  \/>}<br  \/><br  \/><\/code><\/pre>\n<p style=\"padding-top: 8px;padding-bottom: 8px;line-height: 26px;margin-top: 10px;margin-bottom: 10px;font-size: 14px;word-spacing: 2px;\">\u901a\u8fc7\u4ee3\u7801\u53ef\u4ee5\u770b\u5230&nbsp;<strong style=\"color: rgb(145, 109, 213);\">\u300c<span style=\"color:#3eaf7c;\">transient<\/span>\u300d<\/strong>&nbsp;\u4fee\u9970\u7684\u4e00\u4e2a\u5c5e\u6027, \u90a3\u4e48\u5b83\u6709\u4ec0\u4e48\u4f5c\u7528\u5462\uff1f\u6211\u4eec\u901a\u8fc7\u4ee3\u7801\u6765\u9a8c\u8bc1\u4e00\u4e0b\uff1a<\/p>\n<pre style=\"margin-top: 10px;margin-bottom: 10px;border-top-left-radius: 5px;border-top-right-radius: 5px;border-bottom-right-radius: 5px;border-bottom-left-radius: 5px;box-shadow: rgba(0, 0, 0, 0.55) 0px 2px 10px;\"><span style=\"display: block;background-image: url('https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2023\/05\/20230528042704988.jpeg');height: 30px;width: 749px;background-size: 40px;background-color: rgb(40, 44, 52);margin-bottom: -7px;border-top-left-radius: 5px;border-top-right-radius: 5px;border-bottom-right-radius: 5px;border-bottom-left-radius: 5px;background-position: 10px 10px;background-repeat: no-repeat no-repeat;\"><\/span><code style=\"overflow-x: auto;padding: 15px 16px 16px;color: rgb(171, 178, 191);display: -webkit-box;font-family: &quot;Operator Mono&quot;, Consolas, Monaco, Menlo, monospace;font-size: 12px;background-color: rgb(40, 44, 52);border-top-left-radius: 5px;border-top-right-radius: 5px;border-bottom-right-radius: 5px;border-bottom-left-radius: 5px;\">&nbsp;<span style=\"line-height: 26px;\"><span style=\"color: rgb(198, 120, 221);line-height: 26px;\">public<\/span>&nbsp;<span style=\"color: rgb(198, 120, 221);line-height: 26px;\">static<\/span>&nbsp;<span style=\"color: rgb(198, 120, 221);line-height: 26px;\">void<\/span>&nbsp;<span style=\"color: rgb(97, 174, 238);line-height: 26px;\">objSerializable<\/span><span style=\"line-height: 26px;\">()<\/span>&nbsp;<span style=\"color: rgb(198, 120, 221);line-height: 26px;\">throws<\/span>&nbsp;IOException,&nbsp;ClassNotFoundException&nbsp;<\/span>{<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;String&nbsp;objFile&nbsp;=&nbsp;<span style=\"color: rgb(152, 195, 121);line-height: 26px;\">\"test\/apple.txt\"<\/span>;<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Apple&nbsp;apple&nbsp;=&nbsp;<span style=\"color: rgb(198, 120, 221);line-height: 26px;\">new<\/span>&nbsp;Apple(<span style=\"color: rgb(209, 154, 102);line-height: 26px;\">1<\/span>,&nbsp;<span style=\"color: rgb(152, 195, 121);line-height: 26px;\">\"apple\"<\/span>);<br  \/><br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"color: rgb(92, 99, 112);font-style: italic;line-height: 26px;\">\/**<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;\u5e8f\u5217\u5316:<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;&nbsp;&nbsp;1.&nbsp;\u521b\u5efa\u51fa\u8f93\u51fa\u6d41\uff0c\u5373\u76ee\u6807\u5bf9\u8c61\uff0c\u6bd4\u5982\u78c1\u76d8<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;&nbsp;&nbsp;2.&nbsp;\u521b\u5efa\u5bf9\u8c61\u8f93\u51fa\u6d41<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;&nbsp;&nbsp;3.&nbsp;\u5199\u5165\u5bf9\u8c61<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;&nbsp;&nbsp;4.&nbsp;\u5173\u95ed\u5bf9\u8c61\u8f93\u51fa\u6d41<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*\/<\/span><br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;FileOutputStream&nbsp;fileOutputStream&nbsp;=&nbsp;<span style=\"color: rgb(198, 120, 221);line-height: 26px;\">new<\/span>&nbsp;FileOutputStream(objFile);<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ObjectOutputStream&nbsp;objectOutputStream&nbsp;=&nbsp;<span style=\"color: rgb(198, 120, 221);line-height: 26px;\">new<\/span>&nbsp;ObjectOutputStream(fileOutputStream);<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;objectOutputStream.writeObject(apple);<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;objectOutputStream.close();<br  \/><br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"color: rgb(92, 99, 112);font-style: italic;line-height: 26px;\">\/\/&nbsp;\u53d1\u73b0apple.txt\u6587\u4ef6\u6253\u5f00\u540e\u662f\u4e71\u7801\uff0c\u56e0\u4e3a\u88ab\u5e8f\u5217\u5316\u4e86\uff0c\u5bf9\u4e8e\u654f\u611f\u4fe1\u606f\u7684\u5bf9\u8c61\u53ef\u4ee5\u4f7f\u7528\u5e8f\u5217\u5316\u64cd\u4f5c<\/span><br  \/><br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"color: rgb(92, 99, 112);font-style: italic;line-height: 26px;\">\/**<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;&nbsp;\u53cd\u5e8f\u5217\u5316<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;&nbsp;\u4e0e\u5e8f\u5217\u5316\u76f8\u53cd:<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;&nbsp;&nbsp;&nbsp;1.&nbsp;\u521b\u5efa\u8f93\u5165\u6d41<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;&nbsp;&nbsp;&nbsp;2.&nbsp;\u521b\u5efa\u5bf9\u8c61\u8f93\u5165\u6d41<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;&nbsp;&nbsp;&nbsp;3.&nbsp;\u8bfb\u53d6\u5bf9\u8c61<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;&nbsp;&nbsp;&nbsp;4.&nbsp;\u5173\u95ed\u5bf9\u8c61\u8f93\u5165\u6d41<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*\/<\/span><br  \/><br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;FileInputStream&nbsp;fileInputStream&nbsp;=&nbsp;<span style=\"color: rgb(198, 120, 221);line-height: 26px;\">new<\/span>&nbsp;FileInputStream(objFile);<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ObjectInputStream&nbsp;objectInputStream&nbsp;=&nbsp;<span style=\"color: rgb(198, 120, 221);line-height: 26px;\">new<\/span>&nbsp;ObjectInputStream(fileInputStream);<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"color: rgb(92, 99, 112);font-style: italic;line-height: 26px;\">\/\/&nbsp;\u8bfb\u53d6\u5bf9\u8c61<\/span><br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Apple&nbsp;appleRead&nbsp;=&nbsp;(Apple)&nbsp;objectInputStream.readObject();<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;objectInputStream.close();<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Log.info(appleRead);&nbsp;<span style=\"color: rgb(92, 99, 112);font-style: italic;line-height: 26px;\">\/\/&nbsp;x&nbsp;=&nbsp;1&nbsp;&nbsp;y&nbsp;=&nbsp;apple&nbsp;null&nbsp;\u8fd9\u91cc\u6253\u5370\u7684\u662f&nbsp;&nbsp;Apple.toString()&nbsp;\u65b9\u6cd5<\/span><br  \/><br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"color: rgb(92, 99, 112);font-style: italic;line-height: 26px;\">\/\/&nbsp;\u53d1\u73b0&nbsp;transient&nbsp;\u4fee\u9970\u7684z&nbsp;\u5e76\u6ca1\u6709\u88ab\u5e8f\u5217\u5316&nbsp;\uff0c\u6240\u4ee5\u662fnull<\/span><br  \/>&nbsp;&nbsp;&nbsp;&nbsp;}<br  \/>}<br  \/><\/code><\/pre>\n<p style=\"padding-top: 8px;padding-bottom: 8px;line-height: 26px;margin-top: 10px;margin-bottom: 10px;font-size: 14px;word-spacing: 2px;\">\u7ed3\u679c\u5df2\u7ecf\u5728\u6ce8\u91ca\u4e2d\u6807\u8bb0\u4e86~ \u53e6\u5916\u9700\u8981\u63d0\u9192\u5927\u5bb6\u7684\u662f\uff1a&nbsp;<strong style=\"color: rgb(145, 109, 213);\">\u300c<span style=\"color:#3eaf7c;\">\u5e8f\u5217\u5316\u4e0d\u4f1a\u5bf9\u9759\u6001\u53d8\u91cf\u8fdb\u884c\u5e8f\u5217\u5316\uff0c\u56e0\u4e3a\u5e8f\u5217\u5316\u53ea\u662f\u4fdd\u5b58\u5bf9\u8c61\u7684\u72b6\u6001\uff0c\u9759\u6001\u53d8\u91cf\u5c5e\u4e8e\u7c7b\u7684\u72b6\u6001<\/span>\u300d<\/strong><\/p>\n<p style=\"padding-top: 8px;padding-bottom: 8px;line-height: 26px;margin-top: 10px;margin-bottom: 10px;font-size: 14px;word-spacing: 2px;\">\u6211\u4eec\u4e4b\u524d\u5b66\u4e60\u7684\u96c6\u5408&nbsp;<code style=\"word-wrap: break-word;padding: 2px 4px;border-top-left-radius: 4px;border-top-right-radius: 4px;border-bottom-right-radius: 4px;border-bottom-left-radius: 4px;margin-right: 2px;margin-left: 2px;font-family: &quot;Operator Mono&quot;, Consolas, Monaco, Menlo, monospace;word-break: break-all;color: rgb(145, 109, 213);background-image: none;\">ArrayList<\/code>&nbsp;\u5e95\u5c42\u6570\u636e\u7ed3\u6784\u4e2d\u7684\u6570\u7ec4 elementData\u53d8\u91cf\u8fd8\u8bb0\u5f97\u662f\u4ec0\u4e48\u4fee\u9970\u7684\u5417\uff1f\u6ca1\u9519\uff0c\u5c31\u662f&nbsp;<strong style=\"color: rgb(145, 109, 213);\">\u300c<span style=\"color:#3eaf7c;\">transient<\/span>\u300d<\/strong>, \u8fd9\u4e48\u505a\u4e3b\u8981\u662f\u56e0\u4e3a\u8fd9\u4e2a\u6570\u7ec4\u662f\u52a8\u6001\u6269\u5c55\u7684\uff0c\u5e76\u4e0d\u662f\u6240\u6709\u7684\u7a7a\u95f4\u90fd\u88ab\u4f7f\u7528\uff0c\u56e0\u6b64\u5c31\u4e0d\u9700\u8981\u6240\u6709\u7684\u5185\u5bb9\u90fd\u88ab\u5e8f\u5217\u5316\u3002\u901a\u8fc7\u91cd\u5199\u5e8f\u5217\u5316\u548c\u53cd\u5e8f\u5217\u5316\u65b9\u6cd5\uff0c\u4f7f\u5f97\u53ef\u4ee5\u53ea\u5e8f\u5217\u5316\u6570\u7ec4\u4e2d\u6709\u5185\u5bb9\u7684\u90a3\u90e8\u5206\u6570\u636e<\/p>\n<pre style=\"margin-top: 10px;margin-bottom: 10px;border-top-left-radius: 5px;border-top-right-radius: 5px;border-bottom-right-radius: 5px;border-bottom-left-radius: 5px;box-shadow: rgba(0, 0, 0, 0.55) 0px 2px 10px;\"><span style=\"display: block;background-image: url('https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2023\/05\/20230528042704988.jpeg');height: 30px;width: 749px;background-size: 40px;background-color: rgb(40, 44, 52);margin-bottom: -7px;border-top-left-radius: 5px;border-top-right-radius: 5px;border-bottom-right-radius: 5px;border-bottom-left-radius: 5px;background-position: 10px 10px;background-repeat: no-repeat no-repeat;\"><\/span><code style=\"overflow-x: auto;padding: 15px 16px 16px;color: rgb(171, 178, 191);display: -webkit-box;font-family: &quot;Operator Mono&quot;, Consolas, Monaco, Menlo, monospace;font-size: 12px;background-color: rgb(40, 44, 52);border-top-left-radius: 5px;border-top-right-radius: 5px;border-bottom-right-radius: 5px;border-bottom-left-radius: 5px;\"><span style=\"color: rgb(198, 120, 221);line-height: 26px;\">private<\/span>&nbsp;<span style=\"color: rgb(198, 120, 221);line-height: 26px;\">transient<\/span>&nbsp;Object[]&nbsp;elementData;<br  \/><\/code><\/pre>\n<h2 style=\"font-weight: bold;font-size: 22px;margin-top: 20px;margin-right: 10px;\"><span style=\"font-size: 18px;display: inline-block;padding-left: 10px;border-left-width: 5px;border-left-style: solid;border-left-color: rgb(145, 109, 213);\">\u7f51\u7edc\u64cd\u4f5c<\/span><\/h2>\n<p style=\"padding-top: 8px;padding-bottom: 8px;line-height: 26px;margin-top: 10px;margin-bottom: 10px;font-size: 14px;word-spacing: 2px;\">\u4e0a\u8fb9\u7684\u5185\u5bb9\u90fd\u8fd8\u6ca1\u6709\u6d89\u53ca\u5230\u7f51\u7edc\u64cd\u4f5c\uff0c\u4f46\u662f\u6211\u4eec\u7684\u65e5\u5e38\u64cd\u4f5c\u90fd\u662f\u5728\u548c\u7f51\u7edc\u6253\u4ea4\u9053\uff0c\u4e0b\u9762\u6211\u4eec\u5c31\u5f00\u59cb\u5b66\u4e60\u4e00\u4e0b\u7f51\u7edc\u76f8\u5173\u7684IO\u64cd\u4f5c,\u5728Java\u4e2d\u7684\u652f\u6301\u4e3b\u8981\u6709\u4ee5\u4e0b\u51e0\u4e2a\u65b9\u9762:<\/p>\n<ul style=\"margin-top: 8px;margin-bottom: 8px;padding-left: 25px;font-size: 15px;list-style-type: circle;\" class=\"list-paddingleft-2\">\n<li>\n<section style=\"margin-top: 5px;margin-bottom: 5px;line-height: 26px;color: rgb(1, 1, 1);font-size: 14px;\">InetAddress \u7528\u4e8e\u8868\u793a\u7f51\u7edc\u4e0a\u7684\u786c\u4ef6\u8d44\u6e90\uff0c\u5373 IP \u5730\u5740<\/section>\n<\/li>\n<li>\n<section style=\"margin-top: 5px;margin-bottom: 5px;line-height: 26px;color: rgb(1, 1, 1);font-size: 14px;\">URL \u7edf\u4e00\u8d44\u6e90\u5b9a\u4f4d\u7b26<\/section>\n<\/li>\n<li>\n<section style=\"margin-top: 5px;margin-bottom: 5px;line-height: 26px;color: rgb(1, 1, 1);font-size: 14px;\">Socket \u4f7f\u7528 TCP \u534f\u8bae\u5b9e\u73b0\u7f51\u7edc\u901a\u4fe1<\/section>\n<\/li>\n<li>\n<section style=\"margin-top: 5px;margin-bottom: 5px;line-height: 26px;color: rgb(1, 1, 1);font-size: 14px;\">Datagram \u4f7f\u7528 UDP \u534f\u8bae\u5b9e\u73b0\u7f51\u7edc\u901a\u4fe1;<\/section>\n<\/li>\n<\/ul>\n<h3 style=\"margin-top: 30px;margin-bottom: 15px;font-weight: bold;text-align: center;\"><span style=\"border-bottom-width: 2px;border-bottom-style: solid;border-bottom-color: rgb(216, 156, 246);\">InetAddress<\/span><\/h3>\n<p style=\"padding-top: 8px;padding-bottom: 8px;line-height: 26px;margin-top: 10px;margin-bottom: 10px;font-size: 14px;word-spacing: 2px;\">\u8fd9\u4e2a\u7c7b\u6ca1\u6709\u516c\u6709\u7684\u6784\u9020\u51fd\u6570\uff0c\u53ea\u80fd\u901a\u8fc7\u9759\u6001\u65b9\u6cd5\u6765\u521b\u5efa\u5b9e\u4f8b\u3002<\/p>\n<pre style=\"margin-top: 10px;margin-bottom: 10px;border-top-left-radius: 5px;border-top-right-radius: 5px;border-bottom-right-radius: 5px;border-bottom-left-radius: 5px;box-shadow: rgba(0, 0, 0, 0.55) 0px 2px 10px;\"><span style=\"display: block;background-image: url('https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2023\/05\/20230528042704988.jpeg');height: 30px;width: 749px;background-size: 40px;background-color: rgb(40, 44, 52);margin-bottom: -7px;border-top-left-radius: 5px;border-top-right-radius: 5px;border-bottom-right-radius: 5px;border-bottom-left-radius: 5px;background-position: 10px 10px;background-repeat: no-repeat no-repeat;\"><\/span><code style=\"overflow-x: auto;padding: 15px 16px 16px;color: rgb(171, 178, 191);display: -webkit-box;font-family: &quot;Operator Mono&quot;, Consolas, Monaco, Menlo, monospace;font-size: 12px;background-color: rgb(40, 44, 52);border-top-left-radius: 5px;border-top-right-radius: 5px;border-bottom-right-radius: 5px;border-bottom-left-radius: 5px;\">&nbsp;<span style=\"line-height: 26px;\"><span style=\"color: rgb(198, 120, 221);line-height: 26px;\">public<\/span>&nbsp;<span style=\"color: rgb(198, 120, 221);line-height: 26px;\">static<\/span>&nbsp;<span style=\"color: rgb(198, 120, 221);line-height: 26px;\">void<\/span>&nbsp;<span style=\"color: rgb(97, 174, 238);line-height: 26px;\">ipAddress<\/span><span style=\"line-height: 26px;\">()<\/span>&nbsp;<span style=\"color: rgb(198, 120, 221);line-height: 26px;\">throws<\/span>&nbsp;UnknownHostException&nbsp;<\/span>{<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;InetAddress&nbsp;netAddress&nbsp;=&nbsp;InetAddress.getByName(<span style=\"color: rgb(152, 195, 121);line-height: 26px;\">\"www.baidu.com\"<\/span>);<br  \/><br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Log.info(netAddress);&nbsp;<span style=\"color: rgb(92, 99, 112);font-style: italic;line-height: 26px;\">\/\/&nbsp;www.baidu.com\/180.101.49.11<\/span><br  \/><br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"color: rgb(92, 99, 112);font-style: italic;line-height: 26px;\">\/\/&nbsp;\u83b7\u53d6ip\u5730\u5740&nbsp;-&nbsp;\u5148\u4ece\u672c\u5730\u7f13\u5b58\u83b7\u53d6\uff0c&nbsp;\u6ca1\u6709\u8d70dns\u670d\u52a1\u5668<\/span><br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Log.info(<span style=\"color: rgb(152, 195, 121);line-height: 26px;\">\"ipv4:&nbsp;\"<\/span>&nbsp;+&nbsp;netAddress.getHostAddress());&nbsp;<span style=\"color: rgb(92, 99, 112);font-style: italic;line-height: 26px;\">\/\/&nbsp;ipv4:&nbsp;180.101.49.11<\/span><br  \/><br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;InetAddress&nbsp;ipAddress&nbsp;=&nbsp;InetAddress.getByName(<span style=\"color: rgb(152, 195, 121);line-height: 26px;\">\"xx.xxx.xxx.xxx\"<\/span>);<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Log.info(ipAddress);&nbsp;<span style=\"color: rgb(92, 99, 112);font-style: italic;line-height: 26px;\">\/\/&nbsp;\/xx.xxx.xxx.xxx<\/span><br  \/>}<br  \/><\/code><\/pre>\n<h3 style=\"margin-top: 30px;margin-bottom: 15px;font-weight: bold;text-align: center;\"><span style=\"border-bottom-width: 2px;border-bottom-style: solid;border-bottom-color: rgb(216, 156, 246);\">URL\u5b9e\u73b0\u4e0b\u8f7d<\/span><\/h3>\n<p style=\"padding-top: 8px;padding-bottom: 8px;line-height: 26px;margin-top: 10px;margin-bottom: 10px;font-size: 14px;word-spacing: 2px;\">\u8fd9\u4e2a\u4e5f\u662f\u6211\u4eec\u65e5\u5e38\u4f7f\u7528\u9891\u7387\u6bd4\u8f83\u9ad8\u7684\u7c7b\uff0c\u90a3\u4e48\u5b83\u7684\u4f5c\u7528\u662f\u5565\u5462\uff1f\u5b83\u53ef\u4ee5\u76f4\u63a5\u4ece URL \u4e2d\u8bfb\u53d6\u5b57\u8282\u6d41\u6570\u636e,\u901a\u5e38\u662f\u4e00\u4e2a\u7f51\u7edc\u901a\u9053\u5730\u5740, \u4e0b\u9762\u6211\u4eec\u6765\u7ed3\u5408\u4e4b\u524d\u5b66\u4e60\u7684\u77e5\u8bc6\u52a8\u624b\u5b9e\u73b0\u4e00\u4e2a\u4e0b\u8f7d\u529f\u80fd<\/p>\n<pre style=\"margin-top: 10px;margin-bottom: 10px;border-top-left-radius: 5px;border-top-right-radius: 5px;border-bottom-right-radius: 5px;border-bottom-left-radius: 5px;box-shadow: rgba(0, 0, 0, 0.55) 0px 2px 10px;\"><span style=\"display: block;background-image: url('https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2023\/05\/20230528042704988.jpeg');height: 30px;width: 749px;background-size: 40px;background-color: rgb(40, 44, 52);margin-bottom: -7px;border-top-left-radius: 5px;border-top-right-radius: 5px;border-bottom-right-radius: 5px;border-bottom-left-radius: 5px;background-position: 10px 10px;background-repeat: no-repeat no-repeat;\"><\/span><code style=\"overflow-x: auto;padding: 15px 16px 16px;color: rgb(171, 178, 191);display: -webkit-box;font-family: &quot;Operator Mono&quot;, Consolas, Monaco, Menlo, monospace;font-size: 12px;background-color: rgb(40, 44, 52);border-top-left-radius: 5px;border-top-right-radius: 5px;border-bottom-right-radius: 5px;border-bottom-left-radius: 5px;\"><br  \/>&nbsp;&nbsp;<span style=\"color: rgb(92, 99, 112);font-style: italic;line-height: 26px;\">\/**<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;URL<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;\u53ef\u4ee5\u76f4\u63a5\u4ece URL \u4e2d\u8bfb\u53d6\u5b57\u8282\u6d41\u6570\u636e\u3002<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;*\/<\/span><br  \/>&nbsp;&nbsp;<span style=\"line-height: 26px;\"><span style=\"color: rgb(198, 120, 221);line-height: 26px;\">public<\/span>&nbsp;<span style=\"color: rgb(198, 120, 221);line-height: 26px;\">static<\/span>&nbsp;<span style=\"color: rgb(198, 120, 221);line-height: 26px;\">void<\/span>&nbsp;<span style=\"color: rgb(97, 174, 238);line-height: 26px;\">readByteByUrl<\/span><span style=\"line-height: 26px;\">()<\/span>&nbsp;<span style=\"color: rgb(198, 120, 221);line-height: 26px;\">throws<\/span>&nbsp;IOException&nbsp;<\/span>{<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"color: rgb(92, 99, 112);font-style: italic;line-height: 26px;\">\/\/&nbsp;\u521b\u5efaurl\u8bfb\u53d6\u5bf9\u8c61&nbsp;\u6ce8\u610f\u8981\u52a0\u534f\u8bae\u5934<\/span><br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;URL&nbsp;url&nbsp;=&nbsp;<span style=\"color: rgb(198, 120, 221);line-height: 26px;\">new<\/span>&nbsp;URL(<span style=\"color: rgb(152, 195, 121);line-height: 26px;\">\"https:\/\/www.baidu.com\"<\/span>);<br  \/><br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"color: rgb(92, 99, 112);font-style: italic;line-height: 26px;\">\/\/&nbsp;\u521b\u5efa\u8f93\u5165\u6d41&nbsp;-&nbsp;\u5b57\u8282<\/span><br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;InputStream&nbsp;inputStream&nbsp;&nbsp;=&nbsp;url.openStream();<br  \/><br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"color: rgb(92, 99, 112);font-style: italic;line-height: 26px;\">\/\/&nbsp;\u521b\u5efa\u8bfb\u53d6\u6d41&nbsp;-&nbsp;\u5b57\u7b26<\/span><br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;InputStreamReader&nbsp;reader&nbsp;=&nbsp;<span style=\"color: rgb(198, 120, 221);line-height: 26px;\">new<\/span>&nbsp;InputStreamReader(inputStream,&nbsp;<span style=\"color: rgb(152, 195, 121);line-height: 26px;\">\"UTF-8\"<\/span>);<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"color: rgb(92, 99, 112);font-style: italic;line-height: 26px;\">\/\/&nbsp;\u521b\u5efa\u7f13\u51b2\u533a\u8bfb\u53d6\u5bf9\u8c61<\/span><br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;BufferedReader&nbsp;readerReader&nbsp;=&nbsp;<span style=\"color: rgb(198, 120, 221);line-height: 26px;\">new<\/span>&nbsp;BufferedReader(reader);<br  \/><br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;String&nbsp;line;<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"color: rgb(92, 99, 112);font-style: italic;line-height: 26px;\">\/\/&nbsp;\u5199\u5165\u6587\u4ef6<\/span><br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;FileOutputStream&nbsp;fileOutputStream&nbsp;=&nbsp;<span style=\"color: rgb(198, 120, 221);line-height: 26px;\">new<\/span>&nbsp;FileOutputStream(<span style=\"color: rgb(152, 195, 121);line-height: 26px;\">\"test\/baidu.html\"<\/span>);<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;OutputStreamWriter&nbsp;writer&nbsp;=&nbsp;<span style=\"color: rgb(198, 120, 221);line-height: 26px;\">new<\/span>&nbsp;OutputStreamWriter(fileOutputStream);<br  \/><br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"color: rgb(198, 120, 221);line-height: 26px;\">while<\/span>&nbsp;((line&nbsp;=&nbsp;readerReader.readLine())&nbsp;!=&nbsp;<span style=\"color: rgb(198, 120, 221);line-height: 26px;\">null<\/span>)&nbsp;{<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Log.info(line);<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;writer.write(line);<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br  \/><br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"color: rgb(92, 99, 112);font-style: italic;line-height: 26px;\">\/\/&nbsp;\u5173\u95ed\u5199\u5165\u6d41<\/span><br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;writer.close();<br  \/><br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"color: rgb(92, 99, 112);font-style: italic;line-height: 26px;\">\/\/&nbsp;\u5173\u95ed\u8bfb\u53d6\u6d41<\/span><br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;readerReader.close();<br  \/><br  \/><br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"color: rgb(92, 99, 112);font-style: italic;line-height: 26px;\">\/**<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;\u4e0b\u8f7d\u56fe\u7247:<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;&nbsp;1.&nbsp;\u901a\u8fc7&nbsp;\u7f51\u7edc\u5730\u5740\u83b7\u53d6\u7f51\u7edc\u8d44\u6e90\u7684\u5b57\u8282\u6d41<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;&nbsp;2.&nbsp;\u5199\u5165\u6587\u4ef6&nbsp;-&nbsp;\u521b\u5efa\u6587\u4ef6\u8f93\u51fa\u6d41<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;&nbsp;3.&nbsp;\u901a\u8fc7&nbsp;url\u6253\u5f00\u8f93\u5165\u6d41\u901a\u9053&nbsp;imgUrl.openStream()<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;&nbsp;4.&nbsp;\u521b\u5efabuffer\u7f13\u51b2\u533a\uff0c&nbsp;\u5c06\u5b57\u8282\u5199\u5165buffer,<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;&nbsp;5.&nbsp;\u6700\u540e\u901a\u8fc7buffer\u7f13\u51b2\u533a\u5c06\u5185\u5bb9\u5199\u5165\u76ee\u6807\u8f93\u51fa\u6d41<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;&nbsp;6.&nbsp;\u5173\u95ed\u8f93\u51fa\u6d41\u901a\u9053<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*\/<\/span><br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;URL&nbsp;imgUrl&nbsp;=&nbsp;<span style=\"color: rgb(198, 120, 221);line-height: 26px;\">new<\/span>&nbsp;URL(<span style=\"color: rgb(152, 195, 121);line-height: 26px;\">\"https:\/\/t7.baidu.com\/it\/u=4162611394,4275913936&amp;fm=193&amp;f=GIF\"<\/span>);<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;InputStream&nbsp;imgInputStream&nbsp;=&nbsp;<span style=\"color: rgb(198, 120, 221);line-height: 26px;\">new<\/span>&nbsp;BufferedInputStream(imgUrl.openStream());<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;FileOutputStream&nbsp;imgStream&nbsp;=&nbsp;<span style=\"color: rgb(198, 120, 221);line-height: 26px;\">new<\/span>&nbsp;FileOutputStream(<span style=\"color: rgb(152, 195, 121);line-height: 26px;\">\"test\/dog.jpg\"<\/span>);<br  \/><br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"color: rgb(198, 120, 221);line-height: 26px;\">byte<\/span>[]&nbsp;buffer&nbsp;=&nbsp;<span style=\"color: rgb(198, 120, 221);line-height: 26px;\">new<\/span>&nbsp;<span style=\"color: rgb(198, 120, 221);line-height: 26px;\">byte<\/span>[<span style=\"color: rgb(209, 154, 102);line-height: 26px;\">1024<\/span>&nbsp;*&nbsp;<span style=\"color: rgb(209, 154, 102);line-height: 26px;\">2<\/span>];<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"color: rgb(198, 120, 221);line-height: 26px;\">int<\/span>&nbsp;cnt;<br  \/><br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"color: rgb(198, 120, 221);line-height: 26px;\">while<\/span>&nbsp;((cnt&nbsp;=&nbsp;imgInputStream.read(buffer,&nbsp;<span style=\"color: rgb(209, 154, 102);line-height: 26px;\">0<\/span>&nbsp;,&nbsp;buffer.length))&nbsp;!=&nbsp;-<span style=\"color: rgb(209, 154, 102);line-height: 26px;\">1<\/span>)&nbsp;{<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;imgStream.write(buffer,&nbsp;<span style=\"color: rgb(209, 154, 102);line-height: 26px;\">0<\/span>,&nbsp;cnt);<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br  \/><br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;writer.close();<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Log.info(<span style=\"color: rgb(152, 195, 121);line-height: 26px;\">\"\u6587\u4ef6\u4e0b\u8f7d\u6210\u529f\"<\/span>);<br  \/>&nbsp;&nbsp;}<br  \/><br  \/><\/code><\/pre>\n<p style=\"padding-top: 8px;padding-bottom: 8px;line-height: 26px;margin-top: 10px;margin-bottom: 10px;font-size: 14px;word-spacing: 2px;\">\u662f\u4e0d\u662f\u53d1\u73b0\u4e4b\u524d\u5b66\u4e60\u7684\u77e5\u8bc6\u70b9\u90fd\u662f\u4e32\u5728\u4e00\u8d77\u7684\uff0c\u6240\u4ee5\u5e73\u65f6\u5de5\u4f5c\u4e5f\u662f\u4e00\u6837\u7684\uff0c\u53ef\u80fd\u4e00\u4e2a\u4e0d\u8d77\u773c\u7684\u529f\u80fd\u6216\u8bb8\u5c31\u662f\u4f60\u5b9e\u73b0\u590d\u6742\u529f\u80fd\u7684\u5c0f\u5173\u952e\u70b9\uff0c\u6240\u4ee5\u8981\u591a\u53bb\u505a\u603b\u7ed3<\/p>\n<h3 style=\"margin-top: 30px;margin-bottom: 15px;font-weight: bold;text-align: center;\"><span style=\"border-bottom-width: 2px;border-bottom-style: solid;border-bottom-color: rgb(216, 156, 246);\">socket<\/span><\/h3>\n<p style=\"padding-top: 8px;padding-bottom: 8px;line-height: 26px;margin-top: 10px;margin-bottom: 10px;font-size: 14px;word-spacing: 2px;\">\u542c\u5230 <span style=\"color:#3eaf7c;\">socket<\/span>\uff0c\u5927\u5bb6\u90fd\u4e0d\u964c\u751f\uff0c\u4f46\u662f\u5230\u5e95\u5565\u662f&nbsp;<code style=\"word-wrap: break-word;padding: 2px 4px;border-top-left-radius: 4px;border-top-right-radius: 4px;border-bottom-right-radius: 4px;border-bottom-left-radius: 4px;margin-right: 2px;margin-left: 2px;font-family: &quot;Operator Mono&quot;, Consolas, Monaco, Menlo, monospace;word-break: break-all;color: rgb(145, 109, 213);background-image: none;\">socket<\/code>\u5462\uff1f\u6211\u4eec\u5e73\u65f6\u65e5\u5e38\u5f00\u53d1\u5927\u90e8\u5206\u90fd\u662f\u5904\u7406&nbsp;<strong style=\"color: rgb(145, 109, 213);\">\u300c<span style=\"color:#3eaf7c;\">http<\/span>\u300d<\/strong>&nbsp;\u8bf7\u6c42,\u8fd9\u90fd\u662f\u5e94\u7528\u5c42\u7684\u3002\u5148\u770b\u767e\u5ea6\u767e\u79d1\u662f\u600e\u4e48\u63cf\u8ff0\u7684<\/p>\n<p style=\"padding-top: 8px;padding-bottom: 8px;line-height: 26px;margin-top: 10px;margin-bottom: 10px;font-size: 14px;word-spacing: 2px;\">::: tip \u6240\u8c13\u5957\u63a5\u5b57(Socket)\uff0c\u5c31\u662f\u5bf9\u7f51\u7edc\u4e2d\u4e0d\u540c\u4e3b\u673a\u4e0a\u7684\u5e94\u7528\u8fdb\u7a0b\u4e4b\u95f4\u8fdb\u884c\u53cc\u5411\u901a\u4fe1\u7684\u7aef\u70b9\u7684\u62bd\u8c61\u3002\u4e00\u4e2a\u5957\u63a5\u5b57\u5c31\u662f\u7f51\u7edc\u4e0a\u8fdb\u7a0b\u901a\u4fe1\u7684\u4e00\u7aef\uff0c\u63d0\u4f9b\u4e86\u5e94\u7528\u5c42\u8fdb\u7a0b\u5229\u7528\u7f51\u7edc\u534f\u8bae\u4ea4\u6362\u6570\u636e\u7684\u673a\u5236\u3002\u4ece\u6240\u5904\u7684\u5730\u4f4d\u6765\u8bb2\uff0c\u5957\u63a5\u5b57\u4e0a\u8054\u5e94\u7528\u8fdb\u7a0b\uff0c\u4e0b\u8054\u7f51\u7edc\u534f\u8bae\u6808\uff0c\u662f\u5e94\u7528\u7a0b\u5e8f\u901a\u8fc7\u7f51\u7edc\u534f\u8bae\u8fdb\u884c\u901a\u4fe1\u7684\u63a5\u53e3\uff0c\u662f\u5e94\u7528\u7a0b\u5e8f\u4e0e\u7f51\u7edc\u534f\u8bae\u6808\u8fdb\u884c\u4ea4\u4e92\u7684\u63a5\u53e3 :::<\/p>\n<p style=\"padding-top: 8px;padding-bottom: 8px;line-height: 26px;margin-top: 10px;margin-bottom: 10px;font-size: 14px;word-spacing: 2px;\">\u597d\u4e86\uff0c\u6211\u4eec\u77e5\u9053\u4e86\u5e73\u65f6\u6240\u8bf4\u7684\u5957\u63a5\u5b57\u5c31\u662f\u6211\u4eec\u7684 <span style=\"color:#3eaf7c;\">socket<\/span>\uff0c\u8fd8\u8bb0\u5f97\u7f51\u7edc\u4e03\u5c42\u6a21\u578b\u662f\u54ea\u4e03\u4e2a\u5417\uff1f\u4ece\u4e0b\u5f80\u4e0a\uff1a<\/p>\n<p style=\"padding-top: 8px;padding-bottom: 8px;line-height: 26px;margin-top: 10px;margin-bottom: 10px;font-size: 14px;word-spacing: 2px;\">::: tip \u7269\u7406\u5c42\uff08\u786c\u4ef6\uff09 -&gt; \u6570\u636e\u94fe\u8def\u5c42(\u7f51\u5361) -&gt; \u7f51\u7edc\u5c42(ip) -&gt; \u4f20\u8f93\u5c42 (tcp\/udp ...) -&gt; \u4f1a\u8bdd\u5c42 -&gt; \u8868\u793a\u5c42 -&gt; \u5e94\u7528\u5c42 :::<\/p>\n<p style=\"padding-top: 8px;padding-bottom: 8px;line-height: 26px;margin-top: 10px;margin-bottom: 10px;font-size: 14px;word-spacing: 2px;\">\u5176\u4e2d&nbsp;<strong style=\"color: rgb(145, 109, 213);\">\u300c<span style=\"color:#3eaf7c;\">socket<\/span>\u300d<\/strong>&nbsp;\u5c5e\u4e8e\u4f20\u8f93\u5c42(\u57fa\u4e8etcp\/ip)\uff0c\u597d\u4e86\u6709\u591a\u4e86\u4e00\u4e2a\u6982\u5ff5\uff0c\u5565\u662ftcp?<\/p>\n<h4 style=\"margin-top: 30px;margin-bottom: 15px;font-weight: bold;font-size: 18px;\">TCP<\/h4>\n<p style=\"padding-top: 8px;padding-bottom: 8px;line-height: 26px;margin-top: 10px;margin-bottom: 10px;font-size: 14px;word-spacing: 2px;\">\u662f\u4e00\u79cd\u9762\u5411\u8fde\u63a5\u7684\u3001\u53ef\u9760\u7684\u3001\u57fa\u4e8e\u5b57\u8282\u6d41\u7684\u4f20\u8f93\u5c42\u901a\u4fe1\u534f\u8bae\uff0cTCP \u5c42\u662f\u4f4d\u4e8e IP \u5c42\u4e4b\u4e0a\uff0c\u5e94\u7528\u5c42\u4e4b\u4e0b\u7684\u4e2d\u95f4\u5c42\u3002TCP\u4fdd\u969c\u4e86\u4e24\u4e2a\u5e94\u7528\u7a0b\u5e8f\u4e4b\u95f4\u7684\u53ef\u9760\u901a\u4fe1\u3002\u901a\u5e38\u7528\u4e8e\u4e92\u8054\u7f51\u534f\u8bae\uff0c\u88ab\u79f0 TCP \/ IP\u3002<\/p>\n<p style=\"padding-top: 8px;padding-bottom: 8px;line-height: 26px;margin-top: 10px;margin-bottom: 10px;font-size: 14px;word-spacing: 2px;\">socket\u662f\u57fa\u4e8e\u5e94\u7528\u670d\u52a1\u4e0eTCP\/IP\u901a\u4fe1\u4e4b\u95f4\u7684\u4e00\u4e2a\u62bd\u8c61\uff0c\u4ed6\u5c06TCP\/IP\u534f\u8bae\u91cc\u9762\u590d\u6742\u7684\u901a\u4fe1\u903b\u8f91\u8fdb\u884c\u5206\u88c5\uff0c\u5bf9\u7528\u6237\u6765\u8bf4\uff0c\u53ea\u8981\u901a\u8fc7\u4e00\u7ec4\u7b80\u5355\u7684API\u5c31\u53ef\u4ee5\u5b9e\u73b0\u7f51\u7edc\u7684\u8fde\u63a5\u3002<\/p>\n<h4 style=\"margin-top: 30px;margin-bottom: 15px;font-weight: bold;font-size: 18px;\">UDP<\/h4>\n<p style=\"padding-top: 8px;padding-bottom: 8px;line-height: 26px;margin-top: 10px;margin-bottom: 10px;font-size: 14px;word-spacing: 2px;\">\u65e2\u7136<code style=\"word-wrap: break-word;padding: 2px 4px;border-top-left-radius: 4px;border-top-right-radius: 4px;border-bottom-right-radius: 4px;border-bottom-left-radius: 4px;margin-right: 2px;margin-left: 2px;font-family: &quot;Operator Mono&quot;, Consolas, Monaco, Menlo, monospace;word-break: break-all;color: rgb(145, 109, 213);background-image: none;\">tcp<\/code>\u662f\u53ef\u9760\u7684\u94fe\u63a5\uff0c\u90a3\u4e48\u6709\u4e0d\u53ef\u9760\u7684\u5417\uff1f\u6709<\/p>\n<p style=\"padding-top: 8px;padding-bottom: 8px;line-height: 26px;margin-top: 10px;margin-bottom: 10px;font-size: 14px;word-spacing: 2px;\">\u5176\u4e2dUDP\u662f\u4e00\u79cd\u9762\u5411\u65e0\u8fde\u63a5\u7684\u4f20\u8f93\u5c42\u534f\u8bae\u3002UDP\u4e0d\u5173\u5fc3\u5bf9\u7aef\u662f\u5426\u771f\u6b63\u6536\u5230\u4e86\u4f20\u9001\u8fc7\u53bb\u7684\u6570\u636e\u3002\u5982\u679c\u9700\u8981\u68c0\u67e5\u5bf9\u7aef\u662f\u5426\u6536\u5230\u5206\u7ec4\u6570\u636e\u5305\uff0c\u6216\u8005\u5bf9\u7aef\u662f\u5426\u8fde\u63a5\u5230\u7f51\u7edc\uff0c\u5219\u9700\u8981\u5728\u5e94\u7528\u7a0b\u5e8f\u4e2d\u5b9e\u73b0\u3002UDP\u5e38\u7528\u5728\u5206\u7ec4\u6570\u636e\u8f83\u5c11\u6216\u591a\u64ad\u3001\u5e7f\u64ad\u901a\u4fe1\u4ee5\u53ca\u89c6\u9891\u901a\u4fe1\u7b49\u591a\u5a92\u4f53\u9886\u57df\u3002<\/p>\n<h3 style=\"margin-top: 30px;margin-bottom: 15px;font-weight: bold;text-align: center;\"><span style=\"border-bottom-width: 2px;border-bottom-style: solid;border-bottom-color: rgb(216, 156, 246);\">socket \u7f16\u7a0b\u5b9e\u73b0<\/span><\/h3>\n<p style=\"padding-top: 8px;padding-bottom: 8px;line-height: 26px;margin-top: 10px;margin-bottom: 10px;font-size: 14px;word-spacing: 2px;\">\u5957\u63a5\u5b57\u4f7f\u7528<code style=\"word-wrap: break-word;padding: 2px 4px;border-top-left-radius: 4px;border-top-right-radius: 4px;border-bottom-right-radius: 4px;border-bottom-left-radius: 4px;margin-right: 2px;margin-left: 2px;font-family: &quot;Operator Mono&quot;, Consolas, Monaco, Menlo, monospace;word-break: break-all;color: rgb(145, 109, 213);background-image: none;\">TCP<\/code>\u63d0\u4f9b\u4e86\u4e24\u53f0\u8ba1\u7b97\u673a\u4e4b\u95f4\u7684\u901a\u4fe1\u673a\u5236\u3002\u5ba2\u6237\u7aef\u7a0b\u5e8f\u521b\u5efa\u4e00\u4e2a\u5957\u63a5\u5b57\uff0c\u5e76\u5c1d\u8bd5\u8fde\u63a5\u670d\u52a1\u5668\u7684\u5957\u63a5\u5b57\u3002\u5f53\u8fde\u63a5\u5efa\u7acb\u65f6\uff0c\u670d\u52a1\u5668\u4f1a\u521b\u5efa\u4e00\u4e2a Socket \u5bf9\u8c61\u3002\u5ba2\u6237\u7aef\u548c\u670d\u52a1\u5668\u73b0\u5728\u53ef\u4ee5\u901a\u8fc7\u5bf9 Socket \u5bf9\u8c61\u7684\u5199\u5165\u548c\u8bfb\u53d6\u6765\u8fdb\u884c\u901a\u4fe1\u3002<\/p>\n<p style=\"padding-top: 8px;padding-bottom: 8px;line-height: 26px;margin-top: 10px;margin-bottom: 10px;font-size: 14px;word-spacing: 2px;\"><code style=\"word-wrap: break-word;padding: 2px 4px;border-top-left-radius: 4px;border-top-right-radius: 4px;border-bottom-right-radius: 4px;border-bottom-left-radius: 4px;margin-right: 2px;margin-left: 2px;font-family: &quot;Operator Mono&quot;, Consolas, Monaco, Menlo, monospace;word-break: break-all;color: rgb(145, 109, 213);background-image: none;\">java.net.Socket<\/code>&nbsp;\u7c7b\u4ee3\u8868\u4e00\u4e2a\u5957\u63a5\u5b57\uff0c\u5e76\u4e14&nbsp;<code style=\"word-wrap: break-word;padding: 2px 4px;border-top-left-radius: 4px;border-top-right-radius: 4px;border-bottom-right-radius: 4px;border-bottom-left-radius: 4px;margin-right: 2px;margin-left: 2px;font-family: &quot;Operator Mono&quot;, Consolas, Monaco, Menlo, monospace;word-break: break-all;color: rgb(145, 109, 213);background-image: none;\">java.net.ServerSocket<\/code>&nbsp;\u7c7b\u4e3a\u670d\u52a1\u5668\u7a0b\u5e8f\u63d0\u4f9b\u4e86\u4e00\u79cd\u6765\u76d1\u542c\u5ba2\u6237\u7aef\uff0c\u5e76\u4e0e\u4ed6\u4eec\u5efa\u7acb\u8fde\u63a5\u7684\u673a\u5236\u3002\u5b9e\u73b0\u6b65\u9aa4\uff1a<\/p>\n<ul style=\"margin-top: 8px;margin-bottom: 8px;padding-left: 25px;font-size: 15px;list-style-type: circle;\" class=\"list-paddingleft-2\">\n<li>\n<section style=\"margin-top: 5px;margin-bottom: 5px;line-height: 26px;color: rgb(1, 1, 1);font-size: 14px;\">\n<p style=\"padding-top: 8px;padding-bottom: 8px;line-height: 26px;color: black;margin-top: 10px;margin-bottom: 10px;word-spacing: 2px;\">\u670d\u52a1\u5668\u5b9e\u4f8b\u5316\u4e00\u4e2a&nbsp;<code style=\"word-wrap: break-word;padding: 2px 4px;border-top-left-radius: 4px;border-top-right-radius: 4px;border-bottom-right-radius: 4px;border-bottom-left-radius: 4px;margin-right: 2px;margin-left: 2px;font-family: &quot;Operator Mono&quot;, Consolas, Monaco, Menlo, monospace;word-break: break-all;color: rgb(145, 109, 213);background-image: none;\">ServerSocket<\/code>&nbsp;\u5bf9\u8c61\uff0c\u8868\u793a\u901a\u8fc7\u670d\u52a1\u5668\u4e0a\u7684\u7aef\u53e3\u901a\u4fe1<\/p>\n<\/section>\n<\/li>\n<li>\n<section style=\"margin-top: 5px;margin-bottom: 5px;line-height: 26px;color: rgb(1, 1, 1);font-size: 14px;\">\n<p style=\"padding-top: 8px;padding-bottom: 8px;line-height: 26px;color: black;margin-top: 10px;margin-bottom: 10px;word-spacing: 2px;\">\u670d\u52a1\u5668\u8c03\u7528&nbsp;<code style=\"word-wrap: break-word;padding: 2px 4px;border-top-left-radius: 4px;border-top-right-radius: 4px;border-bottom-right-radius: 4px;border-bottom-left-radius: 4px;margin-right: 2px;margin-left: 2px;font-family: &quot;Operator Mono&quot;, Consolas, Monaco, Menlo, monospace;word-break: break-all;color: rgb(145, 109, 213);background-image: none;\">ServerSocket<\/code>&nbsp;\u7c7b\u7684&nbsp;<code style=\"word-wrap: break-word;padding: 2px 4px;border-top-left-radius: 4px;border-top-right-radius: 4px;border-bottom-right-radius: 4px;border-bottom-left-radius: 4px;margin-right: 2px;margin-left: 2px;font-family: &quot;Operator Mono&quot;, Consolas, Monaco, Menlo, monospace;word-break: break-all;color: rgb(145, 109, 213);background-image: none;\">accept()<\/code>&nbsp;\u65b9\u6cd5\uff0c\u8be5\u65b9\u6cd5\u5c06\u4e00\u76f4\u7b49\u5f85\uff0c\u76f4\u5230\u5ba2\u6237\u7aef\u8fde\u63a5\u5230\u670d\u52a1\u5668\u4e0a\u7ed9\u5b9a\u7684\u7aef\u53e3<\/p>\n<\/section>\n<\/li>\n<li>\n<section style=\"margin-top: 5px;margin-bottom: 5px;line-height: 26px;color: rgb(1, 1, 1);font-size: 14px;\">\n<p style=\"padding-top: 8px;padding-bottom: 8px;line-height: 26px;color: black;margin-top: 10px;margin-bottom: 10px;word-spacing: 2px;\">\u670d\u52a1\u5668\u6b63\u5728\u7b49\u5f85\u65f6\uff0c\u4e00\u4e2a\u5ba2\u6237\u7aef\u5b9e\u4f8b\u5316\u4e00\u4e2a&nbsp;<code style=\"word-wrap: break-word;padding: 2px 4px;border-top-left-radius: 4px;border-top-right-radius: 4px;border-bottom-right-radius: 4px;border-bottom-left-radius: 4px;margin-right: 2px;margin-left: 2px;font-family: &quot;Operator Mono&quot;, Consolas, Monaco, Menlo, monospace;word-break: break-all;color: rgb(145, 109, 213);background-image: none;\">Socket<\/code>&nbsp;\u5bf9\u8c61\uff0c\u6307\u5b9a\u670d\u52a1\u5668\u540d\u79f0\u548c\u7aef\u53e3\u53f7\u6765\u8bf7\u6c42\u8fde\u63a5<\/p>\n<\/section>\n<\/li>\n<li>\n<section style=\"margin-top: 5px;margin-bottom: 5px;line-height: 26px;color: rgb(1, 1, 1);font-size: 14px;\">\n<p style=\"padding-top: 8px;padding-bottom: 8px;line-height: 26px;color: black;margin-top: 10px;margin-bottom: 10px;word-spacing: 2px;\">Socket \u7c7b\u7684\u6784\u9020\u51fd\u6570\u8bd5\u56fe\u5c06\u5ba2\u6237\u7aef\u8fde\u63a5\u5230\u6307\u5b9a\u7684\u670d\u52a1\u5668\u548c\u7aef\u53e3\u53f7\u3002\u5982\u679c\u901a\u4fe1\u88ab\u5efa\u7acb\uff0c\u5219\u5728\u5ba2\u6237\u7aef\u521b\u5efa\u4e00\u4e2a&nbsp;<code style=\"word-wrap: break-word;padding: 2px 4px;border-top-left-radius: 4px;border-top-right-radius: 4px;border-bottom-right-radius: 4px;border-bottom-left-radius: 4px;margin-right: 2px;margin-left: 2px;font-family: &quot;Operator Mono&quot;, Consolas, Monaco, Menlo, monospace;word-break: break-all;color: rgb(145, 109, 213);background-image: none;\">Socket<\/code>&nbsp;\u5bf9\u8c61\u80fd\u591f\u4e0e\u670d\u52a1\u5668\u8fdb\u884c\u901a\u4fe1<\/p>\n<\/section>\n<\/li>\n<li>\n<section style=\"margin-top: 5px;margin-bottom: 5px;line-height: 26px;color: rgb(1, 1, 1);font-size: 14px;\">\n<p style=\"padding-top: 8px;padding-bottom: 8px;line-height: 26px;color: black;margin-top: 10px;margin-bottom: 10px;word-spacing: 2px;\">\u5728\u670d\u52a1\u5668\u7aef\uff0c<code style=\"word-wrap: break-word;padding: 2px 4px;border-top-left-radius: 4px;border-top-right-radius: 4px;border-bottom-right-radius: 4px;border-bottom-left-radius: 4px;margin-right: 2px;margin-left: 2px;font-family: &quot;Operator Mono&quot;, Consolas, Monaco, Menlo, monospace;word-break: break-all;color: rgb(145, 109, 213);background-image: none;\">accept()<\/code>&nbsp;\u65b9\u6cd5\u8fd4\u56de\u670d\u52a1\u5668\u4e0a\u4e00\u4e2a\u65b0\u7684&nbsp;<code style=\"word-wrap: break-word;padding: 2px 4px;border-top-left-radius: 4px;border-top-right-radius: 4px;border-bottom-right-radius: 4px;border-bottom-left-radius: 4px;margin-right: 2px;margin-left: 2px;font-family: &quot;Operator Mono&quot;, Consolas, Monaco, Menlo, monospace;word-break: break-all;color: rgb(145, 109, 213);background-image: none;\">socket<\/code>&nbsp;\u5f15\u7528\uff0c\u8be5&nbsp;<code style=\"word-wrap: break-word;padding: 2px 4px;border-top-left-radius: 4px;border-top-right-radius: 4px;border-bottom-right-radius: 4px;border-bottom-left-radius: 4px;margin-right: 2px;margin-left: 2px;font-family: &quot;Operator Mono&quot;, Consolas, Monaco, Menlo, monospace;word-break: break-all;color: rgb(145, 109, 213);background-image: none;\">socket<\/code>&nbsp;\u8fde\u63a5\u5230\u5ba2\u6237\u7aef\u7684&nbsp;<code style=\"word-wrap: break-word;padding: 2px 4px;border-top-left-radius: 4px;border-top-right-radius: 4px;border-bottom-right-radius: 4px;border-bottom-left-radius: 4px;margin-right: 2px;margin-left: 2px;font-family: &quot;Operator Mono&quot;, Consolas, Monaco, Menlo, monospace;word-break: break-all;color: rgb(145, 109, 213);background-image: none;\">socket<\/code><\/p>\n<\/section>\n<\/li>\n<\/ul>\n<p style=\"padding-top: 8px;padding-bottom: 8px;line-height: 26px;margin-top: 10px;margin-bottom: 10px;font-size: 14px;word-spacing: 2px;\">\u8fde\u63a5\u5efa\u7acb\u540e\uff0c\u901a\u8fc7\u4f7f\u7528&nbsp;<code style=\"word-wrap: break-word;padding: 2px 4px;border-top-left-radius: 4px;border-top-right-radius: 4px;border-bottom-right-radius: 4px;border-bottom-left-radius: 4px;margin-right: 2px;margin-left: 2px;font-family: &quot;Operator Mono&quot;, Consolas, Monaco, Menlo, monospace;word-break: break-all;color: rgb(145, 109, 213);background-image: none;\">I\/O<\/code>&nbsp;\u6d41\u5728\u8fdb\u884c\u901a\u4fe1\uff0c\u6bcf\u4e00\u4e2asocket\u90fd\u6709\u4e00\u4e2a\u8f93\u51fa\u6d41\u548c\u4e00\u4e2a\u8f93\u5165\u6d41\uff0c\u5ba2\u6237\u7aef\u7684\u8f93\u51fa\u6d41\u8fde\u63a5\u5230\u670d\u52a1\u5668\u7aef\u7684\u8f93\u5165\u6d41\uff0c\u800c\u5ba2\u6237\u7aef\u7684\u8f93\u5165\u6d41\u8fde\u63a5\u5230\u670d\u52a1\u5668\u7aef\u7684\u8f93\u51fa\u6d41\u3002<\/p>\n<p style=\"padding-top: 8px;padding-bottom: 8px;line-height: 26px;margin-top: 10px;margin-bottom: 10px;font-size: 14px;word-spacing: 2px;\"><code style=\"word-wrap: break-word;padding: 2px 4px;border-top-left-radius: 4px;border-top-right-radius: 4px;border-bottom-right-radius: 4px;border-bottom-left-radius: 4px;margin-right: 2px;margin-left: 2px;font-family: &quot;Operator Mono&quot;, Consolas, Monaco, Menlo, monospace;word-break: break-all;color: rgb(145, 109, 213);background-image: none;\">TCP<\/code>&nbsp;\u662f\u4e00\u4e2a\u53cc\u5411\u7684\u901a\u4fe1\u534f\u8bae\uff0c\u56e0\u6b64\u6570\u636e\u53ef\u4ee5\u901a\u8fc7\u4e24\u4e2a\u6570\u636e\u6d41\u5728\u540c\u4e00\u65f6\u95f4\u53d1\u9001.\u4ee5\u4e0b\u662f\u4e00\u4e9b\u7c7b\u63d0\u4f9b\u7684\u4e00\u5957\u5b8c\u6574\u7684\u6709\u7528\u7684\u65b9\u6cd5\u6765\u5b9e\u73b0 socket\u3002<\/p>\n<p style=\"padding-top: 8px;padding-bottom: 8px;line-height: 26px;margin-top: 10px;margin-bottom: 10px;font-size: 14px;word-spacing: 2px;\">\u4e0b\u9762\u6211\u4eec\u624b\u52a8\u5b9e\u73b0\u4e00\u4e0b\uff0c\u6211\u4eec\u5148\u5b9e\u73b0 ````\u5ba2\u6237\u7aef``` \uff1a<\/p>\n<pre style=\"margin-top: 10px;margin-bottom: 10px;border-top-left-radius: 5px;border-top-right-radius: 5px;border-bottom-right-radius: 5px;border-bottom-left-radius: 5px;box-shadow: rgba(0, 0, 0, 0.55) 0px 2px 10px;\"><span style=\"display: block;background-image: url('https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2023\/05\/20230528042704988.jpeg');height: 30px;width: 749px;background-size: 40px;background-color: rgb(40, 44, 52);margin-bottom: -7px;border-top-left-radius: 5px;border-top-right-radius: 5px;border-bottom-right-radius: 5px;border-bottom-left-radius: 5px;background-position: 10px 10px;background-repeat: no-repeat no-repeat;\"><\/span><code style=\"overflow-x: auto;padding: 15px 16px 16px;color: rgb(171, 178, 191);display: -webkit-box;font-family: &quot;Operator Mono&quot;, Consolas, Monaco, Menlo, monospace;font-size: 12px;background-color: rgb(40, 44, 52);border-top-left-radius: 5px;border-top-right-radius: 5px;border-bottom-right-radius: 5px;border-bottom-left-radius: 5px;\">&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"color: rgb(92, 99, 112);font-style: italic;line-height: 26px;\">\/\/&nbsp;\u5ba2\u6237\u7aefsocket<\/span><br  \/>&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"line-height: 26px;\"><span style=\"color: rgb(198, 120, 221);line-height: 26px;\">public<\/span>&nbsp;<span style=\"color: rgb(198, 120, 221);line-height: 26px;\">static<\/span>&nbsp;<span style=\"color: rgb(198, 120, 221);line-height: 26px;\">void<\/span>&nbsp;<span style=\"color: rgb(97, 174, 238);line-height: 26px;\">clientSocket<\/span><span style=\"line-height: 26px;\">()<\/span>&nbsp;<span style=\"color: rgb(198, 120, 221);line-height: 26px;\">throws<\/span>&nbsp;IOException&nbsp;<\/span>{<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"color: rgb(198, 120, 221);line-height: 26px;\">int<\/span>&nbsp;port&nbsp;=&nbsp;<span style=\"color: rgb(209, 154, 102);line-height: 26px;\">1000<\/span>;<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;String&nbsp;host&nbsp;=&nbsp;<span style=\"color: rgb(152, 195, 121);line-height: 26px;\">\"localhost\"<\/span>;<br  \/><br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"color: rgb(92, 99, 112);font-style: italic;line-height: 26px;\">\/\/&nbsp;\u521b\u5efa\u5957\u63a5\u5b57<\/span><br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Socket&nbsp;socket&nbsp;=&nbsp;<span style=\"color: rgb(198, 120, 221);line-height: 26px;\">new<\/span>&nbsp;Socket(host,&nbsp;port);<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"color: rgb(92, 99, 112);font-style: italic;line-height: 26px;\">\/\/&nbsp;\u5982\u679c\u94fe\u63a5\u4e0d\u4e0a\u4f1a\u62a5\u9519&nbsp;&nbsp;Connection&nbsp;refused&nbsp;(Connection&nbsp;refused)<\/span><br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Log.info(<span style=\"color: rgb(152, 195, 121);line-height: 26px;\">\"\u94fe\u63a5\u5230\u8fdc\u7a0b\u4e3b\u673a\u5730\u5740\uff1a&nbsp;\"<\/span>&nbsp;+&nbsp;socket.getRemoteSocketAddress());<br  \/><br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"color: rgb(92, 99, 112);font-style: italic;line-height: 26px;\">\/\/&nbsp;\u83b7\u53d6\u5957\u63a5\u5b57\u8f93\u51fa\u6d41<\/span><br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;OutputStream&nbsp;outputStream&nbsp;=&nbsp;socket.getOutputStream();<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"color: rgb(92, 99, 112);font-style: italic;line-height: 26px;\">\/\/&nbsp;\u5efa\u7acb\u6570\u636e\u8f93\u51fa\u6d41<\/span><br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;DataOutputStream&nbsp;dataOutputStream&nbsp;=&nbsp;<span style=\"color: rgb(198, 120, 221);line-height: 26px;\">new<\/span>&nbsp;DataOutputStream(outputStream);<br  \/><br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"color: rgb(92, 99, 112);font-style: italic;line-height: 26px;\">\/\/&nbsp;\u5199\u5165\u6570\u636e&nbsp;-&nbsp;\u5199\u5165\u5b57\u7b26\u6570\u636e<\/span><br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;dataOutputStream.writeUTF(<span style=\"color: rgb(152, 195, 121);line-height: 26px;\">\"\u6211\u662f\u5ba2\u6237\u7aef&nbsp;socket\"<\/span>);<br  \/><br  \/><br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"color: rgb(92, 99, 112);font-style: italic;line-height: 26px;\">\/\/&nbsp;\u83b7\u53d6\u670d\u52a1\u7aef\u7684\u54cd\u5e94<\/span><br  \/><br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"color: rgb(92, 99, 112);font-style: italic;line-height: 26px;\">\/\/&nbsp;\u83b7\u53d6\u8f93\u5165\u6d41<\/span><br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;InputStream&nbsp;inputStream&nbsp;=&nbsp;socket.getInputStream();<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"color: rgb(92, 99, 112);font-style: italic;line-height: 26px;\">\/\/&nbsp;\u521b\u5efa\u6570\u636e\u8f93\u5165\u6d41<\/span><br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;DataInputStream&nbsp;dataInputStream&nbsp;=&nbsp;<span style=\"color: rgb(198, 120, 221);line-height: 26px;\">new<\/span>&nbsp;DataInputStream(inputStream);<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"color: rgb(92, 99, 112);font-style: italic;line-height: 26px;\">\/\/&nbsp;\u8bfb\u53d6\u6570\u636e<\/span><br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Log.info(dataInputStream.readUTF());<br  \/><br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"color: rgb(92, 99, 112);font-style: italic;line-height: 26px;\">\/\/&nbsp;\u5173\u95ed\u5ba2\u6237\u7aef<\/span><br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;socket.close();<br  \/>&nbsp;&nbsp;}<br  \/><\/code><\/pre>\n<p style=\"padding-top: 8px;padding-bottom: 8px;line-height: 26px;margin-top: 10px;margin-bottom: 10px;font-size: 14px;word-spacing: 2px;\">\u670d\u52a1\u7aef\uff1a<\/p>\n<pre style=\"margin-top: 10px;margin-bottom: 10px;border-top-left-radius: 5px;border-top-right-radius: 5px;border-bottom-right-radius: 5px;border-bottom-left-radius: 5px;box-shadow: rgba(0, 0, 0, 0.55) 0px 2px 10px;\"><span style=\"display: block;background-image: url('https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2023\/05\/20230528042704988.jpeg');height: 30px;width: 749px;background-size: 40px;background-color: rgb(40, 44, 52);margin-bottom: -7px;border-top-left-radius: 5px;border-top-right-radius: 5px;border-bottom-right-radius: 5px;border-bottom-left-radius: 5px;background-position: 10px 10px;background-repeat: no-repeat no-repeat;\"><\/span><code style=\"overflow-x: auto;padding: 15px 16px 16px;color: rgb(171, 178, 191);display: -webkit-box;font-family: &quot;Operator Mono&quot;, Consolas, Monaco, Menlo, monospace;font-size: 12px;background-color: rgb(40, 44, 52);border-top-left-radius: 5px;border-top-right-radius: 5px;border-bottom-right-radius: 5px;border-bottom-left-radius: 5px;\">&nbsp;<span style=\"color: rgb(92, 99, 112);font-style: italic;line-height: 26px;\">\/\/&nbsp;\u670d\u52a1\u7aefsocket<\/span><br  \/>&nbsp;&nbsp;<span style=\"line-height: 26px;\"><span style=\"color: rgb(198, 120, 221);line-height: 26px;\">public<\/span>&nbsp;<span style=\"color: rgb(198, 120, 221);line-height: 26px;\">static<\/span>&nbsp;<span style=\"color: rgb(198, 120, 221);line-height: 26px;\">void<\/span>&nbsp;<span style=\"color: rgb(97, 174, 238);line-height: 26px;\">serverSocket<\/span><span style=\"line-height: 26px;\">()<\/span>&nbsp;<span style=\"color: rgb(198, 120, 221);line-height: 26px;\">throws<\/span>&nbsp;IOException&nbsp;<\/span>{<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"color: rgb(92, 99, 112);font-style: italic;line-height: 26px;\">\/\/&nbsp;\u521b\u5efa\u670d\u52a1\u7aef<\/span><br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ServerSocket&nbsp;serverSocket&nbsp;=&nbsp;<span style=\"color: rgb(198, 120, 221);line-height: 26px;\">new<\/span>&nbsp;ServerSocket(<span style=\"color: rgb(209, 154, 102);line-height: 26px;\">1000<\/span>);<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"color: rgb(92, 99, 112);font-style: italic;line-height: 26px;\">\/\/&nbsp;\u8bbe\u7f6e\u8d85\u65f6\u65f6\u95f4&nbsp;ms&nbsp;-&nbsp;30s&nbsp;\u5185\u672a\u6536\u5230\u6d88\u606f\u81ea\u52a8\u9000\u51fa<\/span><br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;serverSocket.setSoTimeout(<span style=\"color: rgb(209, 154, 102);line-height: 26px;\">30000<\/span>);<br  \/><br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"color: rgb(198, 120, 221);line-height: 26px;\">while<\/span>(<span style=\"color: rgb(198, 120, 221);line-height: 26px;\">true<\/span>)&nbsp;{<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"color: rgb(198, 120, 221);line-height: 26px;\">try<\/span>&nbsp;{<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Log.info(<span style=\"color: rgb(152, 195, 121);line-height: 26px;\">\"\u7b49\u5f85\u8fdc\u7a0b\u8fde\u63a5----&gt;\"<\/span>&nbsp;+&nbsp;serverSocket.getLocalPort());&nbsp;<span style=\"color: rgb(92, 99, 112);font-style: italic;line-height: 26px;\">\/\/&nbsp;\u7b49\u5f85\u8fdc\u7a0b\u8fde\u63a5----&gt;1000<\/span><br  \/><br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"color: rgb(92, 99, 112);font-style: italic;line-height: 26px;\">\/\/&nbsp;\u83b7\u53d6\u670d\u52a1\u7aef\u5957\u63a5\u5b57<\/span><br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Socket&nbsp;socket&nbsp;=&nbsp;serverSocket.accept();<br  \/><br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Log.info(<span style=\"color: rgb(152, 195, 121);line-height: 26px;\">\"\u8fdc\u7a0b\u4e3b\u673a\u5730\u5740:&nbsp;----&gt;\"<\/span>&nbsp;+&nbsp;socket.getRemoteSocketAddress());<br  \/><br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"color: rgb(92, 99, 112);font-style: italic;line-height: 26px;\">\/\/&nbsp;\u83b7\u53d6\u5ba2\u6237\u7aef\u54cd\u5e94<\/span><br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"color: rgb(92, 99, 112);font-style: italic;line-height: 26px;\">\/\/&nbsp;\u521b\u5efa\u8f93\u5165\u6d41<\/span><br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;DataInputStream&nbsp;dataInputStream&nbsp;=&nbsp;<span style=\"color: rgb(198, 120, 221);line-height: 26px;\">new<\/span>&nbsp;DataInputStream(socket.getInputStream());<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Log.info(<span style=\"color: rgb(152, 195, 121);line-height: 26px;\">\"\u5ba2\u6237\u7aef\u8bf4\u4e86:&nbsp;----&gt;\"<\/span>&nbsp;+&nbsp;dataInputStream.readUTF());<br  \/><br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"color: rgb(92, 99, 112);font-style: italic;line-height: 26px;\">\/\/&nbsp;\u53d1\u9001\u6d88\u606f\u7ed9\u5ba2\u6237\u7aef<\/span><br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;OutputStream&nbsp;outputStream&nbsp;=&nbsp;socket.getOutputStream();<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;DataOutputStream&nbsp;dataOutputStream&nbsp;=&nbsp;<span style=\"color: rgb(198, 120, 221);line-height: 26px;\">new<\/span>&nbsp;DataOutputStream(outputStream);<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;dataOutputStream.writeUTF(<span style=\"color: rgb(152, 195, 121);line-height: 26px;\">\"\u6211\u6536\u5230\u4e86\u4f60\u7684\u6d88\u606f&nbsp;\/&nbsp;server&nbsp;Socket\"<\/span>);<br  \/><br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;socket.close();<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br  \/><span style=\"color: rgb(92, 99, 112);font-style: italic;line-height: 26px;\">\/\/&nbsp;\u76f8\u5173\u8f93\u51fa:<\/span><br  \/><br  \/><span style=\"color: rgb(92, 99, 112);font-style: italic;line-height: 26px;\">\/\/&nbsp;&nbsp;\u670d\u52a1\u7aef:<\/span><br  \/><span style=\"color: rgb(92, 99, 112);font-style: italic;line-height: 26px;\">\/\/&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\u7b49\u5f85\u8fdc\u7a0b\u8fde\u63a5----&gt;1000<\/span><br  \/><span style=\"color: rgb(92, 99, 112);font-style: italic;line-height: 26px;\">\/\/&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\u8fdc\u7a0b\u4e3b\u673a\u5730\u5740:&nbsp;----&gt;\/127.0.0.1:59773<\/span><br  \/><span style=\"color: rgb(92, 99, 112);font-style: italic;line-height: 26px;\">\/\/&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\u5ba2\u6237\u7aef\u8bf4\u4e86:&nbsp;----&gt;\u6211\u662f\u5ba2\u6237\u7aef&nbsp;socket<\/span><br  \/><span style=\"color: rgb(92, 99, 112);font-style: italic;line-height: 26px;\">\/\/&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\u7b49\u5f85\u8fdc\u7a0b\u8fde\u63a5----&gt;1000<\/span><br  \/><span style=\"color: rgb(92, 99, 112);font-style: italic;line-height: 26px;\">\/\/&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\u8fdc\u7a0b\u4e3b\u673a\u5730\u5740:&nbsp;----&gt;\/127.0.0.1:59778<\/span><br  \/><span style=\"color: rgb(92, 99, 112);font-style: italic;line-height: 26px;\">\/\/&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\u5ba2\u6237\u7aef\u8bf4\u4e86:&nbsp;----&gt;\u6211\u662f\u5ba2\u6237\u7aef&nbsp;socket<\/span><br  \/><span style=\"color: rgb(92, 99, 112);font-style: italic;line-height: 26px;\">\/\/&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\u7b49\u5f85\u8fdc\u7a0b\u8fde\u63a5----&gt;1000<\/span><br  \/><br  \/><br  \/><span style=\"color: rgb(92, 99, 112);font-style: italic;line-height: 26px;\">\/\/&nbsp;\u5ba2\u6237\u7aef:<\/span><br  \/><span style=\"color: rgb(92, 99, 112);font-style: italic;line-height: 26px;\">\/\/&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\u94fe\u63a5\u5230\u8fdc\u7a0b\u4e3b\u673a\u5730\u5740\uff1alocalhost\/127.0.0.1:1000<\/span><br  \/><span style=\"color: rgb(92, 99, 112);font-style: italic;line-height: 26px;\">\/\/&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\u6211\u6536\u5230\u4e86\u4f60\u7684\u6d88\u606f&nbsp;\/&nbsp;server&nbsp;Socket<\/span><br  \/><br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<span style=\"color: rgb(198, 120, 221);line-height: 26px;\">catch<\/span>&nbsp;(IOException&nbsp;e)&nbsp;{<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Log.info(<span style=\"color: rgb(152, 195, 121);line-height: 26px;\">\"\u670d\u52a1\u7aef\u51fa\u9519\u4e86&nbsp;----&gt;&nbsp;\"<\/span>&nbsp;+&nbsp;e.getMessage());<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"color: rgb(198, 120, 221);line-height: 26px;\">break<\/span>;<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;}<br  \/><\/code><\/pre>\n<h3 style=\"margin-top: 30px;margin-bottom: 15px;font-weight: bold;text-align: center;\"><span style=\"border-bottom-width: 2px;border-bottom-style: solid;border-bottom-color: rgb(216, 156, 246);\">UDP\u5b9e\u73b0<\/span><\/h3>\n<p style=\"padding-top: 8px;padding-bottom: 8px;line-height: 26px;margin-top: 10px;margin-bottom: 10px;font-size: 14px;word-spacing: 2px;\">\u6211\u4eec\u4e4b\u524d\u63d0\u5230\u8fc7&nbsp;<code style=\"word-wrap: break-word;padding: 2px 4px;border-top-left-radius: 4px;border-top-right-radius: 4px;border-bottom-right-radius: 4px;border-bottom-left-radius: 4px;margin-right: 2px;margin-left: 2px;font-family: &quot;Operator Mono&quot;, Consolas, Monaco, Menlo, monospace;word-break: break-all;color: rgb(145, 109, 213);background-image: none;\">udp<\/code>, \u6240\u4ee5\u8fd9\u91cc\u6211\u4eec\u4e5f\u52a8\u624b\u5b9e\u73b0\u4e00\u4e0b,\u6838\u5fc3\u7c7b\u4e3b\u8981\u662f\u4ee5\u4e0b:<\/p>\n<ul style=\"margin-top: 8px;margin-bottom: 8px;padding-left: 25px;font-size: 15px;list-style-type: circle;\" class=\"list-paddingleft-2\">\n<li>\n<section style=\"margin-top: 5px;margin-bottom: 5px;line-height: 26px;color: rgb(1, 1, 1);font-size: 14px;\">Datagram<\/section>\n<\/li>\n<li>\n<section style=\"margin-top: 5px;margin-bottom: 5px;line-height: 26px;color: rgb(1, 1, 1);font-size: 14px;\">DatagramSocket\uff1a\u901a\u4fe1\u7c7b<\/section>\n<\/li>\n<li>\n<section style=\"margin-top: 5px;margin-bottom: 5px;line-height: 26px;color: rgb(1, 1, 1);font-size: 14px;\">DatagramPacket\uff1a\u6570\u636e\u5305\u7c7b(\u5e73\u65f6\u8bf4\u7684\u4e22\u5305\u5565\u7684\uff0c\u4e22\u7684\u5c31\u662f\u6570\u636e\u5305)<\/section>\n<\/li>\n<\/ul>\n<p style=\"padding-top: 8px;padding-bottom: 8px;line-height: 26px;margin-top: 10px;margin-bottom: 10px;font-size: 14px;word-spacing: 2px;\"><code style=\"word-wrap: break-word;padding: 2px 4px;border-top-left-radius: 4px;border-top-right-radius: 4px;border-bottom-right-radius: 4px;border-bottom-left-radius: 4px;margin-right: 2px;margin-left: 2px;font-family: &quot;Operator Mono&quot;, Consolas, Monaco, Menlo, monospace;word-break: break-all;color: rgb(145, 109, 213);background-image: none;\">\u7eb8\u4e0a\u5f97\u6765\u7ec8\u89c9\u6d45\u554a<\/code>\uff0c\u8fd9\u6b21\u5462\uff0c\u6211\u4eec\u6311\u6218\u4e00\u4e0b\u81ea\u5df1\uff0c\u6211\u4eec\u4e0d\u4f20\u5b57\u7b26\u4e32\u4e86\uff0c\u6211\u4eec\u6765\u4f20\u6587\u4ef6\uff0c\u8fd9\u600e\u4e48\u53bb\u5b9e\u73b0\u5462, \u8fd9\u5c31\u8003\u9a8c\u6211\u4eec\u4e4b\u524d\u5b66\u7684\u600e\u4e48\u6837\u4e86, \u8fd8\u662f\u4e00\u6837\u7684\uff0c\u6211\u4eec\u5148\u5b9e\u73b0&nbsp;<code style=\"word-wrap: break-word;padding: 2px 4px;border-top-left-radius: 4px;border-top-right-radius: 4px;border-bottom-right-radius: 4px;border-bottom-left-radius: 4px;margin-right: 2px;margin-left: 2px;font-family: &quot;Operator Mono&quot;, Consolas, Monaco, Menlo, monospace;word-break: break-all;color: rgb(145, 109, 213);background-image: none;\">\u5ba2\u6237\u7aef<\/code><\/p>\n<pre style=\"margin-top: 10px;margin-bottom: 10px;border-top-left-radius: 5px;border-top-right-radius: 5px;border-bottom-right-radius: 5px;border-bottom-left-radius: 5px;box-shadow: rgba(0, 0, 0, 0.55) 0px 2px 10px;\"><span style=\"display: block;background-image: url('https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2023\/05\/20230528042704988.jpeg');height: 30px;width: 749px;background-size: 40px;background-color: rgb(40, 44, 52);margin-bottom: -7px;border-top-left-radius: 5px;border-top-right-radius: 5px;border-bottom-right-radius: 5px;border-bottom-left-radius: 5px;background-position: 10px 10px;background-repeat: no-repeat no-repeat;\"><\/span><code style=\"overflow-x: auto;padding: 15px 16px 16px;color: rgb(171, 178, 191);display: -webkit-box;font-family: &quot;Operator Mono&quot;, Consolas, Monaco, Menlo, monospace;font-size: 12px;background-color: rgb(40, 44, 52);border-top-left-radius: 5px;border-top-right-radius: 5px;border-bottom-right-radius: 5px;border-bottom-left-radius: 5px;\">&nbsp;<span style=\"line-height: 26px;\"><span style=\"color: rgb(198, 120, 221);line-height: 26px;\">public<\/span>&nbsp;<span style=\"color: rgb(198, 120, 221);line-height: 26px;\">static<\/span>&nbsp;<span style=\"color: rgb(198, 120, 221);line-height: 26px;\">void<\/span>&nbsp;<span style=\"color: rgb(97, 174, 238);line-height: 26px;\">dataGramClient<\/span><span style=\"line-height: 26px;\">()<\/span>&nbsp;<span style=\"color: rgb(198, 120, 221);line-height: 26px;\">throws<\/span>&nbsp;IOException&nbsp;<\/span>{<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"color: rgb(92, 99, 112);font-style: italic;line-height: 26px;\">\/\/&nbsp;\u521b\u5efa\u4e00\u4e2a\u6570\u636e\u5305\u5bf9\u8c61&nbsp;\u5e76\u7ed1\u5b9a\u5230\u5185\u6838ip<\/span><br  \/>&nbsp;&nbsp;&nbsp;&nbsp;DatagramSocket&nbsp;socket&nbsp;=&nbsp;<span style=\"color: rgb(198, 120, 221);line-height: 26px;\">new<\/span>&nbsp;DatagramSocket(<span style=\"color: rgb(209, 154, 102);line-height: 26px;\">1001<\/span>);<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;Log.info(<span style=\"color: rgb(152, 195, 121);line-height: 26px;\">\"client:&nbsp;\"<\/span>&nbsp;+&nbsp;socket.getLocalAddress());<br  \/><br  \/>&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"color: rgb(92, 99, 112);font-style: italic;line-height: 26px;\">\/\/&nbsp;\u5199\u5165\u6570\u636e\u5230\u5305<\/span><br  \/>&nbsp;&nbsp;&nbsp;&nbsp;FileInputStream&nbsp;fileInputStream&nbsp;=&nbsp;<span style=\"color: rgb(198, 120, 221);line-height: 26px;\">new<\/span>&nbsp;FileInputStream(<span style=\"color: rgb(152, 195, 121);line-height: 26px;\">\"test\/dog.jpg\"<\/span>);<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"color: rgb(198, 120, 221);line-height: 26px;\">byte<\/span>[]&nbsp;buffer&nbsp;=&nbsp;<span style=\"color: rgb(198, 120, 221);line-height: 26px;\">new<\/span>&nbsp;<span style=\"color: rgb(198, 120, 221);line-height: 26px;\">byte<\/span>[<span style=\"color: rgb(209, 154, 102);line-height: 26px;\">1024<\/span>&nbsp;*&nbsp;<span style=\"color: rgb(209, 154, 102);line-height: 26px;\">2<\/span>];<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"color: rgb(92, 99, 112);font-style: italic;line-height: 26px;\">\/\/&nbsp;\u5982\u679c\u662f\u6570\u636e\u91cf\u5927\uff0c&nbsp;\u6bd4\u5982\u6587\u4ef6\u53ef\u4ee5\u5229\u7528&nbsp;buffer&nbsp;stream&nbsp;\u501f\u7528\u7f13\u51b2\u533a\u53bb\u8bfb\u53d6\u6570\u636e<\/span><br  \/>&nbsp;&nbsp;&nbsp;&nbsp;BufferedInputStream&nbsp;bufferedInputStream&nbsp;=&nbsp;<span style=\"color: rgb(198, 120, 221);line-height: 26px;\">new<\/span>&nbsp;BufferedInputStream(fileInputStream);<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"color: rgb(198, 120, 221);line-height: 26px;\">int<\/span>&nbsp;cnt;<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"color: rgb(198, 120, 221);line-height: 26px;\">while<\/span>((cnt&nbsp;=&nbsp;bufferedInputStream.read(buffer,&nbsp;<span style=\"color: rgb(209, 154, 102);line-height: 26px;\">0<\/span>,&nbsp;buffer.length))&nbsp;!=&nbsp;-<span style=\"color: rgb(209, 154, 102);line-height: 26px;\">1<\/span>)&nbsp;{<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"color: rgb(92, 99, 112);font-style: italic;line-height: 26px;\">\/\/&nbsp;\u5c01\u5305<\/span><br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;DatagramPacket&nbsp;dp&nbsp;=&nbsp;<span style=\"color: rgb(198, 120, 221);line-height: 26px;\">new<\/span>&nbsp;DatagramPacket(buffer,&nbsp;<span style=\"color: rgb(209, 154, 102);line-height: 26px;\">0<\/span>,&nbsp;cnt);<br  \/><br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"color: rgb(92, 99, 112);font-style: italic;line-height: 26px;\">\/\/&nbsp;\u53d1\u9001\u5305&nbsp;-&nbsp;Message&nbsp;too&nbsp;long&nbsp;(sendto&nbsp;failed)&nbsp;udp&nbsp;\u652f\u6301\u7684\u5305\u6700\u5927\u662f&nbsp;64k<\/span><br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"color: rgb(92, 99, 112);font-style: italic;line-height: 26px;\">\/\/&nbsp;dp.setData(buffer);&nbsp;\/\/&nbsp;\u5982\u679c\u521d\u59cb\u5316\u597d\u7684\uff0c&nbsp;\u5c31\u4e0d\u7528setData<\/span><br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;dp.setAddress(InetAddress.getLocalHost());<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;dp.setPort(<span style=\"color: rgb(209, 154, 102);line-height: 26px;\">1002<\/span>);<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;socket.send(dp);<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Log.info(<span style=\"color: rgb(152, 195, 121);line-height: 26px;\">\"\u4f20\u8f93\u4e2d...\"<\/span>);<br  \/><br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"color: rgb(92, 99, 112);font-style: italic;line-height: 26px;\">\/\/&nbsp;cnt&nbsp;\u7b49\u4e8ebuffer.length<\/span><br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Log.info(<span style=\"color: rgb(152, 195, 121);line-height: 26px;\">\"buffer&nbsp;read&nbsp;index&nbsp;---&gt;\"<\/span>);<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;}<br  \/><br  \/>&nbsp;&nbsp;&nbsp;&nbsp;Log.info(<span style=\"color: rgb(152, 195, 121);line-height: 26px;\">\"\u4f20\u8f93\u5b8c\u6bd5\"<\/span>);<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"color: rgb(92, 99, 112);font-style: italic;line-height: 26px;\">\/\/&nbsp;\u5173\u95ed\u8f93\u5165\u6d41&nbsp;-&nbsp;\u4e0d\u7136\u4f1a\u5bfc\u81f4\u963b\u585e<\/span><br  \/>&nbsp;&nbsp;&nbsp;&nbsp;bufferedInputStream.close();<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;Log.info(<span style=\"color: rgb(152, 195, 121);line-height: 26px;\">\"close\"<\/span>);<br  \/><br  \/>&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"color: rgb(92, 99, 112);font-style: italic;line-height: 26px;\">\/\/&nbsp;\u53d1\u5b8c\u540e\u53d1\u9001\u4e00\u4e2a\u7ed3\u675f\u7684\u6307\u4ee4<\/span><br  \/>&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"color: rgb(198, 120, 221);line-height: 26px;\">byte<\/span>[]&nbsp;successData&nbsp;=&nbsp;<span style=\"color: rgb(152, 195, 121);line-height: 26px;\">\"FILE&nbsp;OK\"<\/span>.getBytes(StandardCharsets.UTF_8);<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;DatagramPacket&nbsp;successPak&nbsp;=&nbsp;<span style=\"color: rgb(198, 120, 221);line-height: 26px;\">new<\/span>&nbsp;DatagramPacket(successData,&nbsp;<span style=\"color: rgb(209, 154, 102);line-height: 26px;\">0<\/span>,&nbsp;successData.length);<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;successPak.setAddress(InetAddress.getLocalHost());<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;successPak.setPort(<span style=\"color: rgb(209, 154, 102);line-height: 26px;\">1002<\/span>);<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;socket.send(successPak);<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;Log.info(<span style=\"color: rgb(152, 195, 121);line-height: 26px;\">\"send\"<\/span>);<br  \/><br  \/>&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"color: rgb(92, 99, 112);font-style: italic;line-height: 26px;\">\/\/&nbsp;\u521b\u5efa\u4e00\u4e2a\u5305&nbsp;1M&nbsp;\u5927\u5c0f<\/span><br  \/>&nbsp;&nbsp;&nbsp;&nbsp;DatagramPacket&nbsp;packet&nbsp;=&nbsp;<span style=\"color: rgb(198, 120, 221);line-height: 26px;\">new<\/span>&nbsp;DatagramPacket(<span style=\"color: rgb(198, 120, 221);line-height: 26px;\">new<\/span>&nbsp;<span style=\"color: rgb(198, 120, 221);line-height: 26px;\">byte<\/span>[<span style=\"color: rgb(209, 154, 102);line-height: 26px;\">1024<\/span>],&nbsp;<span style=\"color: rgb(209, 154, 102);line-height: 26px;\">1024<\/span>);<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"color: rgb(92, 99, 112);font-style: italic;line-height: 26px;\">\/\/&nbsp;\u8bbe\u7f6e\u8fdc\u7a0b\u4e3b\u673a&nbsp;-&nbsp;\u7528\u4e8e\u6570\u636e\u4e0a\u62a5\u548c\u63a5\u6536<\/span><br  \/>&nbsp;&nbsp;&nbsp;&nbsp;packet.setPort(<span style=\"color: rgb(209, 154, 102);line-height: 26px;\">1002<\/span>);<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;packet.setAddress(InetAddress.getLocalHost());<br  \/><br  \/>&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"color: rgb(92, 99, 112);font-style: italic;line-height: 26px;\">\/\/&nbsp;\u63a5\u6536\u5305&nbsp;-&nbsp;\u5982\u679c\u6ca1\u63a5\u6536\u5230&nbsp;\u4f1a\u963b\u585e<\/span><br  \/>&nbsp;&nbsp;&nbsp;&nbsp;socket.receive(packet);<br  \/><br  \/>&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"color: rgb(92, 99, 112);font-style: italic;line-height: 26px;\">\/\/&nbsp;\u83b7\u53d6\u6570\u636e<\/span><br  \/>&nbsp;&nbsp;&nbsp;&nbsp;Log.info(packet.getAddress()&nbsp;+&nbsp;<span style=\"color: rgb(152, 195, 121);line-height: 26px;\">\"&nbsp;---&gt;&nbsp;\"<\/span>+&nbsp;<span style=\"color: rgb(198, 120, 221);line-height: 26px;\">new<\/span>&nbsp;String(packet.getData(),&nbsp;<span style=\"color: rgb(152, 195, 121);line-height: 26px;\">\"UTF-8\"<\/span>));<br  \/><br  \/>&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"color: rgb(92, 99, 112);font-style: italic;line-height: 26px;\">\/\/&nbsp;\u5173\u95ed\u5ba2\u6237\u7aef<\/span><br  \/>&nbsp;&nbsp;&nbsp;&nbsp;socket.close();<br  \/>}<br  \/><\/code><\/pre>\n<p style=\"padding-top: 8px;padding-bottom: 8px;line-height: 26px;margin-top: 10px;margin-bottom: 10px;font-size: 14px;word-spacing: 2px;\">\u5728\u770b\u4e00\u4e0b&nbsp;<code style=\"word-wrap: break-word;padding: 2px 4px;border-top-left-radius: 4px;border-top-right-radius: 4px;border-bottom-right-radius: 4px;border-bottom-left-radius: 4px;margin-right: 2px;margin-left: 2px;font-family: &quot;Operator Mono&quot;, Consolas, Monaco, Menlo, monospace;word-break: break-all;color: rgb(145, 109, 213);background-image: none;\">\u670d\u52a1\u7aef<\/code><\/p>\n<pre style=\"margin-top: 10px;margin-bottom: 10px;border-top-left-radius: 5px;border-top-right-radius: 5px;border-bottom-right-radius: 5px;border-bottom-left-radius: 5px;box-shadow: rgba(0, 0, 0, 0.55) 0px 2px 10px;\"><span style=\"display: block;background-image: url('https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2023\/05\/20230528042704988.jpeg');height: 30px;width: 749px;background-size: 40px;background-color: rgb(40, 44, 52);margin-bottom: -7px;border-top-left-radius: 5px;border-top-right-radius: 5px;border-bottom-right-radius: 5px;border-bottom-left-radius: 5px;background-position: 10px 10px;background-repeat: no-repeat no-repeat;\"><\/span><code style=\"overflow-x: auto;padding: 15px 16px 16px;color: rgb(171, 178, 191);display: -webkit-box;font-family: &quot;Operator Mono&quot;, Consolas, Monaco, Menlo, monospace;font-size: 12px;background-color: rgb(40, 44, 52);border-top-left-radius: 5px;border-top-right-radius: 5px;border-bottom-right-radius: 5px;border-bottom-left-radius: 5px;\">&nbsp;<span style=\"color: rgb(92, 99, 112);font-style: italic;line-height: 26px;\">\/\/&nbsp;\u670d\u52a1\u7aef<\/span><br  \/>&nbsp;&nbsp;<span style=\"line-height: 26px;\"><span style=\"color: rgb(198, 120, 221);line-height: 26px;\">public<\/span>&nbsp;<span style=\"color: rgb(198, 120, 221);line-height: 26px;\">static<\/span>&nbsp;<span style=\"color: rgb(198, 120, 221);line-height: 26px;\">void<\/span>&nbsp;<span style=\"color: rgb(97, 174, 238);line-height: 26px;\">dataGramServer<\/span><span style=\"line-height: 26px;\">()<\/span>&nbsp;<span style=\"color: rgb(198, 120, 221);line-height: 26px;\">throws<\/span>&nbsp;IOException&nbsp;<\/span>{<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"color: rgb(92, 99, 112);font-style: italic;line-height: 26px;\">\/\/&nbsp;\u521b\u5efa\u4e00\u4e2a\u6570\u636e\u5305\u5bf9\u8c61&nbsp;\u5e76\u7ed1\u5b9a\u5230\u5185\u6838ip<\/span><br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;DatagramSocket&nbsp;socket&nbsp;=&nbsp;<span style=\"color: rgb(198, 120, 221);line-height: 26px;\">new<\/span>&nbsp;DatagramSocket(<span style=\"color: rgb(209, 154, 102);line-height: 26px;\">1002<\/span>);<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Log.info(<span style=\"color: rgb(152, 195, 121);line-height: 26px;\">\"server:&nbsp;\"<\/span>&nbsp;+&nbsp;socket.getLocalAddress());<br  \/><br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"color: rgb(92, 99, 112);font-style: italic;line-height: 26px;\">\/\/&nbsp;\u521b\u5efa\u6587\u4ef6\u8f93\u51fa\u6d41<\/span><br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;FileOutputStream&nbsp;fos&nbsp;=&nbsp;<span style=\"color: rgb(198, 120, 221);line-height: 26px;\">new<\/span>&nbsp;FileOutputStream(<span style=\"color: rgb(152, 195, 121);line-height: 26px;\">\"test\/dog1.jpg\"<\/span>);<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"color: rgb(92, 99, 112);font-style: italic;line-height: 26px;\">\/\/&nbsp;\u521b\u5efa\u4e00\u4e2a\u8f93\u51fa\u6d41<\/span><br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;BufferedOutputStream&nbsp;bos&nbsp;=&nbsp;<span style=\"color: rgb(198, 120, 221);line-height: 26px;\">new<\/span>&nbsp;BufferedOutputStream(fos);<br  \/><br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"color: rgb(198, 120, 221);line-height: 26px;\">byte<\/span>[]&nbsp;buffer&nbsp;=&nbsp;<span style=\"color: rgb(198, 120, 221);line-height: 26px;\">new<\/span>&nbsp;<span style=\"color: rgb(198, 120, 221);line-height: 26px;\">byte<\/span>[<span style=\"color: rgb(209, 154, 102);line-height: 26px;\">1024<\/span>&nbsp;*&nbsp;<span style=\"color: rgb(209, 154, 102);line-height: 26px;\">2<\/span>];<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"color: rgb(198, 120, 221);line-height: 26px;\">while<\/span>&nbsp;(<span style=\"color: rgb(198, 120, 221);line-height: 26px;\">true<\/span>)&nbsp;{<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"color: rgb(92, 99, 112);font-style: italic;line-height: 26px;\">\/\/&nbsp;\u89e3\u5305<\/span><br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;DatagramPacket&nbsp;fileDp&nbsp;=&nbsp;<span style=\"color: rgb(198, 120, 221);line-height: 26px;\">new<\/span>&nbsp;DatagramPacket(buffer,&nbsp;<span style=\"color: rgb(209, 154, 102);line-height: 26px;\">0<\/span>,&nbsp;buffer.length);<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;fileDp.setPort(<span style=\"color: rgb(209, 154, 102);line-height: 26px;\">1001<\/span>);<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;fileDp.setAddress(InetAddress.getLocalHost());<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;socket.receive(fileDp);<br  \/><br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"color: rgb(92, 99, 112);font-style: italic;line-height: 26px;\">\/\/&nbsp;\u5224\u65ad\u662f\u5426\u63a5\u6536\u5230\u6587\u4ef6\u4e0a\u4f20\u5b8c\u6bd5\u6307\u4ee4<\/span><br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"color: rgb(198, 120, 221);line-height: 26px;\">if<\/span>(<span style=\"color: rgb(198, 120, 221);line-height: 26px;\">new<\/span>&nbsp;String(fileDp.getData(),&nbsp;<span style=\"color: rgb(152, 195, 121);line-height: 26px;\">\"UTF-8\"<\/span>).contains(<span style=\"color: rgb(152, 195, 121);line-height: 26px;\">\"FILE&nbsp;OK\"<\/span>))&nbsp;{<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Log.info(<span style=\"color: rgb(152, 195, 121);line-height: 26px;\">\"\u6587\u4ef6\u63a5\u6536\u5b8c\u6bd5\"<\/span>);<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"color: rgb(198, 120, 221);line-height: 26px;\">break<\/span>;<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br  \/><br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"color: rgb(92, 99, 112);font-style: italic;line-height: 26px;\">\/\/&nbsp;\u5199\u5165\u6587\u4ef6<\/span><br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;bos.write(buffer,&nbsp;<span style=\"color: rgb(209, 154, 102);line-height: 26px;\">0<\/span>,&nbsp;buffer.length);<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;bos.flush();<br  \/><br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Log.info(<span style=\"color: rgb(152, 195, 121);line-height: 26px;\">\"\u6b63\u5728\u63a5\u6536\u6570\u636e&nbsp;-&gt;\"<\/span>);<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br  \/><br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"color: rgb(92, 99, 112);font-style: italic;line-height: 26px;\">\/\/&nbsp;\u5173\u95ed\u8f93\u51fa\u6d41<\/span><br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;bos.close();<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Log.info(<span style=\"color: rgb(152, 195, 121);line-height: 26px;\">\"\u6587\u4ef6\u53e5\u67c4\u5173\u95ed\"<\/span>);<br  \/><br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"color: rgb(92, 99, 112);font-style: italic;line-height: 26px;\">\/\/&nbsp;\u8bbe\u7f6e\u6570\u636e<\/span><br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"color: rgb(198, 120, 221);line-height: 26px;\">byte<\/span>[]&nbsp;result&nbsp;=&nbsp;<span style=\"color: rgb(152, 195, 121);line-height: 26px;\">\"\u6211\u5df2\u7ecf\u4e0b\u8f7d\u597d\u4e86\u6587\u4ef6\"<\/span>.getBytes(StandardCharsets.UTF_8);<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;DatagramPacket&nbsp;resPck&nbsp;=&nbsp;<span style=\"color: rgb(198, 120, 221);line-height: 26px;\">new<\/span>&nbsp;DatagramPacket(result,&nbsp;<span style=\"color: rgb(209, 154, 102);line-height: 26px;\">0<\/span>,&nbsp;result.length);<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;resPck.setPort(<span style=\"color: rgb(209, 154, 102);line-height: 26px;\">1001<\/span>);<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;resPck.setAddress(InetAddress.getLocalHost());<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"color: rgb(92, 99, 112);font-style: italic;line-height: 26px;\">\/\/&nbsp;\u53d1\u9001\u6570\u636e\u7ed9\u5ba2\u6237\u7aef&nbsp;-&nbsp;\u53d1\u5305<\/span><br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;socket.send(resPck);<br  \/><br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Log.info(<span style=\"color: rgb(152, 195, 121);line-height: 26px;\">\"\u53d1\u9001\u7ed3\u679c\"<\/span>);<br  \/><br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"color: rgb(92, 99, 112);font-style: italic;line-height: 26px;\">\/\/&nbsp;\u5173\u95ed\u670d\u52a1\u7aef<\/span><br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;socket.close();<br  \/>&nbsp;&nbsp;}<br  \/><\/code><\/pre>\n<p style=\"padding-top: 8px;padding-bottom: 8px;line-height: 26px;margin-top: 10px;margin-bottom: 10px;font-size: 14px;word-spacing: 2px;\">\u7531\u6b64\uff0c\u6211\u4eec\u8fd9\u4e2a\u5c0f\u529f\u80fd\u5c31\u7b97\u5b9e\u73b0\u4e86~<\/p>\n<h2 style=\"font-weight: bold;font-size: 22px;margin-top: 20px;margin-right: 10px;\"><span style=\"font-size: 18px;display: inline-block;padding-left: 10px;border-left-width: 5px;border-left-style: solid;border-left-color: rgb(145, 109, 213);\">NIO<\/span><\/h2>\n<p style=\"padding-top: 8px;padding-bottom: 8px;line-height: 26px;margin-top: 10px;margin-bottom: 10px;font-size: 14px;word-spacing: 2px;\">\u4e4b\u524d\u7684\u6848\u4f8b\u4e2d\uff0c\u6709\u63d0\u5230<code style=\"word-wrap: break-word;padding: 2px 4px;border-top-left-radius: 4px;border-top-right-radius: 4px;border-bottom-right-radius: 4px;border-bottom-left-radius: 4px;margin-right: 2px;margin-left: 2px;font-family: &quot;Operator Mono&quot;, Consolas, Monaco, Menlo, monospace;word-break: break-all;color: rgb(145, 109, 213);background-image: none;\">\u963b\u585e<\/code>, \u6ca1\u6709\u600e\u4e48\u7ec6\u8bb2\uff0c\u4e0b\u9762\u6211\u4eec\u5c31\u8bf4\u8bf4\u51e0\u79cdIO\u6a21\u5f0f\uff0c\u5728\u4e86\u89e3\u8fd9\u4e2a\u4e4b\u524d\u5462\uff0c\u6211\u4eec\u5148\u6765\u804a\u804a\u4ec0\u4e48\u662f<code style=\"word-wrap: break-word;padding: 2px 4px;border-top-left-radius: 4px;border-top-right-radius: 4px;border-bottom-right-radius: 4px;border-bottom-left-radius: 4px;margin-right: 2px;margin-left: 2px;font-family: &quot;Operator Mono&quot;, Consolas, Monaco, Menlo, monospace;word-break: break-all;color: rgb(145, 109, 213);background-image: none;\">\u540c\u6b65<\/code>&nbsp;\u548c&nbsp;<code style=\"word-wrap: break-word;padding: 2px 4px;border-top-left-radius: 4px;border-top-right-radius: 4px;border-bottom-right-radius: 4px;border-bottom-left-radius: 4px;margin-right: 2px;margin-left: 2px;font-family: &quot;Operator Mono&quot;, Consolas, Monaco, Menlo, monospace;word-break: break-all;color: rgb(145, 109, 213);background-image: none;\">\u5f02\u6b65<\/code><\/p>\n<h3 style=\"margin-top: 30px;margin-bottom: 15px;font-weight: bold;text-align: center;\"><span style=\"border-bottom-width: 2px;border-bottom-style: solid;border-bottom-color: rgb(216, 156, 246);\">\u540c\u6b65 &amp; \u5f02\u6b65<\/span><\/h3>\n<p style=\"padding-top: 8px;padding-bottom: 8px;line-height: 26px;margin-top: 10px;margin-bottom: 10px;font-size: 14px;word-spacing: 2px;\">\u540c\u6b65\u548c\u5f02\u6b65\u662f\u9488\u5bf9\u5e94\u7528\u7a0b\u5e8f\u548c\u5185\u6838\u7684\u4ea4\u4e92\u800c\u8a00\u7684\uff0c\u540c\u6b65\u6307\u7684\u662f\u7528\u6237\u8fdb\u7a0b\u89e6\u53d1IO \u64cd\u4f5c\u5e76\u7b49\u5f85\u6216\u8005\u8f6e\u8be2\u7684\u53bb\u67e5\u770bIO \u64cd\u4f5c\u662f\u5426\u5c31\u7eea\uff0c\u800c\u5f02\u6b65\u662f\u6307\u7528\u6237\u8fdb\u7a0b\u89e6\u53d1IO \u64cd\u4f5c\u4ee5\u540e\u4fbf\u5f00\u59cb\u505a\u81ea\u5df1\u7684\u4e8b\u60c5\uff0c\u800c\u5f53IO \u64cd\u4f5c\u5df2\u7ecf\u5b8c\u6210\u7684\u65f6\u5019\u4f1a\u5f97\u5230IO \u5b8c\u6210\u7684\u901a\u77e5\u3002<\/p>\n<p style=\"padding-top: 8px;padding-bottom: 8px;line-height: 26px;margin-top: 10px;margin-bottom: 10px;font-size: 14px;word-spacing: 2px;\">\u5927\u767d\u8bdd\u8bb2\u5c31\u662f,\u4e3e\u4e2a\u94f6\u884c\u7684\u4f8b\u5b50:<\/p>\n<ul style=\"margin-top: 8px;margin-bottom: 8px;padding-left: 25px;font-size: 15px;list-style-type: circle;\" class=\"list-paddingleft-2\">\n<li>\n<section style=\"margin-top: 5px;margin-bottom: 5px;line-height: 26px;color: rgb(1, 1, 1);font-size: 14px;\">\n<p style=\"padding-top: 8px;padding-bottom: 8px;line-height: 26px;color: black;margin-top: 10px;margin-bottom: 10px;word-spacing: 2px;\"><code style=\"word-wrap: break-word;padding: 2px 4px;border-top-left-radius: 4px;border-top-right-radius: 4px;border-bottom-right-radius: 4px;border-bottom-left-radius: 4px;margin-right: 2px;margin-left: 2px;font-family: &quot;Operator Mono&quot;, Consolas, Monaco, Menlo, monospace;word-break: break-all;color: rgb(145, 109, 213);background-image: none;\">\u540c\u6b65<\/code>&nbsp;\uff1a\u81ea\u5df1\u4eb2\u81ea\u51fa\u9a6c\u6301\u94f6\u884c\u5361\u5230\u94f6\u884c\u53d6\u94b1\uff08\u4f7f\u7528\u540c\u6b65 IO \u65f6\uff0cJava \u81ea\u5df1\u5904\u7406IO \u8bfb\u5199\uff09\uff1b<\/p>\n<\/section>\n<\/li>\n<li>\n<section style=\"margin-top: 5px;margin-bottom: 5px;line-height: 26px;color: rgb(1, 1, 1);font-size: 14px;\">\n<p style=\"padding-top: 8px;padding-bottom: 8px;line-height: 26px;color: black;margin-top: 10px;margin-bottom: 10px;word-spacing: 2px;\"><code style=\"word-wrap: break-word;padding: 2px 4px;border-top-left-radius: 4px;border-top-right-radius: 4px;border-bottom-right-radius: 4px;border-bottom-left-radius: 4px;margin-right: 2px;margin-left: 2px;font-family: &quot;Operator Mono&quot;, Consolas, Monaco, Menlo, monospace;word-break: break-all;color: rgb(145, 109, 213);background-image: none;\">\u5f02\u6b65<\/code>&nbsp;\uff1a\u59d4\u6258\u4e00\u5c0f\u5f1f\u62ff\u94f6\u884c\u5361\u5230\u94f6\u884c\u53d6\u94b1\uff0c\u7136\u540e\u7ed9\u4f60\uff08\u4f7f\u7528\u5f02\u6b65IO \u65f6\uff0cJava \u5c06 IO \u8bfb\u5199\u59d4\u6258\u7ed9OS \u5904\u7406\uff0c\u9700\u8981\u5c06\u6570\u636e\u7f13\u51b2\u533a\u5730\u5740\u548c\u5927\u5c0f\u4f20\u7ed9OS(\u94f6\u884c\u5361\u548c\u5bc6\u7801)\uff0cOS \u9700\u8981\u652f\u6301\u5f02\u6b65IO\u64cd\u4f5cAPI\uff09<\/p>\n<\/section>\n<\/li>\n<\/ul>\n<h3 style=\"margin-top: 30px;margin-bottom: 15px;font-weight: bold;text-align: center;\"><span style=\"border-bottom-width: 2px;border-bottom-style: solid;border-bottom-color: rgb(216, 156, 246);\">\u963b\u585e &amp; \u5f02\u6b65<\/span><\/h3>\n<p style=\"padding-top: 8px;padding-bottom: 8px;line-height: 26px;margin-top: 10px;margin-bottom: 10px;font-size: 14px;word-spacing: 2px;\">\u963b\u585e\u548c\u975e\u963b\u585e\u662f\u9488\u5bf9\u4e8e\u8fdb\u7a0b\u5728\u8bbf\u95ee\u6570\u636e\u7684\u65f6\u5019\uff0c\u6839\u636eIO\u64cd\u4f5c\u7684\u5c31\u7eea\u72b6\u6001\u6765\u91c7\u53d6\u7684\u4e0d\u540c\u65b9\u5f0f\uff0c\u8bf4\u767d\u4e86\u662f\u4e00\u79cd\u8bfb\u53d6\u6216\u8005\u5199\u5165\u64cd\u4f5c\u65b9\u6cd5\u7684\u5b9e\u73b0\u65b9\u5f0f\uff0c\u963b\u585e\u65b9\u5f0f\u4e0b\u8bfb\u53d6\u6216\u8005\u5199\u5165\u51fd\u6570\u5c06\u4e00\u76f4\u7b49\u5f85\uff0c\u800c\u975e\u963b\u585e\u65b9\u5f0f\u4e0b\uff0c\u8bfb\u53d6\u6216\u8005\u5199\u5165\u65b9\u6cd5\u4f1a\u7acb\u5373\u8fd4\u56de\u4e00\u4e2a\u72b6\u6001\u503c\u3002<\/p>\n<p style=\"padding-top: 8px;padding-bottom: 8px;line-height: 26px;margin-top: 10px;margin-bottom: 10px;font-size: 14px;word-spacing: 2px;\">\u8fd8\u662f\u4e0a\u8fb9\u7684\u4f8b\u5b50:<\/p>\n<ul style=\"margin-top: 8px;margin-bottom: 8px;padding-left: 25px;font-size: 15px;list-style-type: circle;\" class=\"list-paddingleft-2\">\n<li>\n<section style=\"margin-top: 5px;margin-bottom: 5px;line-height: 26px;color: rgb(1, 1, 1);font-size: 14px;\">\n<p style=\"padding-top: 8px;padding-bottom: 8px;line-height: 26px;color: black;margin-top: 10px;margin-bottom: 10px;word-spacing: 2px;\">\u963b\u585e \uff1aATM\u6392\u961f\u53d6\u6b3e\uff0c\u4f60\u53ea\u80fd\u7b49\u5f85<\/p>\n<\/section>\n<\/li>\n<li>\n<section style=\"margin-top: 5px;margin-bottom: 5px;line-height: 26px;color: rgb(1, 1, 1);font-size: 14px;\">\n<p style=\"padding-top: 8px;padding-bottom: 8px;line-height: 26px;color: black;margin-top: 10px;margin-bottom: 10px;word-spacing: 2px;\">\u975e\u963b\u585e \uff1a\u67dc\u53f0\u53d6\u6b3e\uff0c\u53d6\u4e2a\u53f7\uff0c\u7136\u540e\u5750\u5728\u6905\u5b50\u4e0a\u505a\u5176\u5b83\u4e8b\uff0c\u7b49\u53f7\u5e7f\u64ad\u4f1a\u901a\u77e5\u4f60\u529e\u7406\uff0c\u6ca1\u5230\u53f7\u4f60\u5c31\u4e0d\u80fd\u53bb\uff0c\u4f60\u53ef\u4ee5\u4e0d\u65ad\u95ee\u670d\u52a1\u4eba\u5458\u6392\u5230\u4e86\u6ca1\u6709,\u670d\u52a1\u4eba\u5458\u5982\u679c\u8bf4\u8fd8\u6ca1\u5230\u4f60\u5c31\u4e0d\u80fd\u53bb<\/p>\n<\/section>\n<\/li>\n<\/ul>\n<p style=\"padding-top: 8px;padding-bottom: 8px;line-height: 26px;margin-top: 10px;margin-bottom: 10px;font-size: 14px;word-spacing: 2px;\">\u597d\u4e86\uff0c\u6709\u4e86\u4e0a\u9762\u6982\u5ff5\u7684\u7406\u89e3\uff0c\u5927\u6982\u4f60\u4f1a\u731c\u5230\u6709\u54ea\u4e9b\u6a21\u5f0f\u4e86\u3002\u6ca1\u9519\uff0c\u6211\u4eec\u6765\u4e00\u8d77\u7ec4\u8bcd<\/p>\n<h3 style=\"margin-top: 30px;margin-bottom: 15px;font-weight: bold;text-align: center;\"><span style=\"border-bottom-width: 2px;border-bottom-style: solid;border-bottom-color: rgb(216, 156, 246);\">\u540c\u6b65\u963b\u585e BIO (Blocking IO)<\/span><\/h3>\n<p style=\"padding-top: 8px;padding-bottom: 8px;line-height: 26px;margin-top: 10px;margin-bottom: 10px;font-size: 14px;word-spacing: 2px;\">\u8fd9\u662f\u6211\u4eec\u6bd4\u8f83\u5e38\u89c1\u7684\u65b9\u5f0f, BIO\u7f16\u7a0b\u65b9\u5f0f\u901a\u5e38\u662f\u5728JDK1.4\u7248\u672c\u4e4b\u524d\u5e38\u7528\u7684\u7f16\u7a0b\u65b9\u5f0f\u3002\u7f16\u7a0b\u5b9e\u73b0\u8fc7\u7a0b\u4e3a\uff1a\u9996\u5148\u5728\u670d\u52a1\u7aef\u542f\u52a8\u4e00\u4e2aServerSocket\u6765\u76d1\u542c\u7f51\u7edc\u8bf7\u6c42\uff0c\u5ba2\u6237\u7aef\u542f\u52a8Socket\u53d1\u8d77\u7f51\u7edc\u8bf7\u6c42\uff0c\u9ed8\u8ba4\u60c5\u51b5\u4e0bServerSocket\u56de\u5efa\u7acb\u4e00\u4e2a\u7ebf\u7a0b\u6765\u5904\u7406\u6b64\u8bf7\u6c42\uff0c\u5982\u679c\u670d\u52a1\u7aef\u6ca1\u6709\u7ebf\u7a0b\u53ef\u7528\uff0c\u5ba2\u6237\u7aef\u5219\u4f1a\u963b\u585e\u7b49\u5f85\u6216\u906d\u5230\u62d2\u7edd\u3002\u4e14\u5efa\u7acb\u597d\u7684\u8fde\u63a5\uff0c\u5728\u901a\u8baf\u8fc7\u7a0b\u4e2d\uff0c\u662f\u540c\u6b65\u7684\u3002\u5728\u5e76\u53d1\u5904\u7406\u6548\u7387\u4e0a\u6bd4\u8f83\u4f4e\u3002\u5927\u81f4\u7ed3\u6784\u5982\u4e0b\uff1a<\/p>\n<p style=\"padding-top: 8px;padding-bottom: 8px;line-height: 26px;margin-top: 10px;margin-bottom: 10px;font-size: 14px;word-spacing: 2px;\">\u540c\u6b65\u5e76\u963b\u585e\uff0c\u670d\u52a1\u5668\u5b9e\u73b0\u6a21\u5f0f\u4e3a\u4e00\u4e2a\u8fde\u63a5\u4e00\u4e2a\u7ebf\u7a0b\uff0c\u5373\u5ba2\u6237\u7aef\u6709\u8fde\u63a5\u8bf7\u6c42\u65f6\u670d\u52a1\u5668\u7aef\u5c31\u9700\u8981\u542f\u52a8\u4e00\u4e2a\u7ebf\u7a0b\u8fdb\u884c\u5904\u7406\uff0c \u5982\u679c\u8fd9\u4e2a\u8fde\u63a5\u4e0d\u505a\u4efb\u4f55\u4e8b\u60c5\u4f1a\u9020\u6210\u4e0d\u5fc5\u8981\u7684\u7ebf\u7a0b\u5f00\u9500\uff0c\u5f53\u7136\u53ef\u4ee5\u901a\u8fc7\u7ebf\u7a0b\u6c60\u673a\u5236\u6539\u5584\u3002BIO\u65b9\u5f0f\u9002\u7528\u4e8e\u8fde\u63a5\u6570\u76ee\u6bd4\u8f83\u5c0f\u4e14\u56fa\u5b9a\u7684\u67b6\u6784\uff0c\u8fd9\u79cd\u65b9\u5f0f\u5bf9\u670d\u52a1\u5668\u8d44\u6e90\u8981\u6c42\u6bd4\u8f83\u9ad8\uff0c\u5e76\u53d1\u5c40\u9650\u4e8e\u5e94\u7528\u4e2d\uff0cJDK1.4\u4ee5\u524d\u7684\u552f\u4e00\u9009\u62e9\uff0c\u4f46\u7a0b\u5e8f\u76f4\u89c2\u7b80\u5355\u6613\u7406\u89e3\u3002<\/p>\n<h3 style=\"margin-top: 30px;margin-bottom: 15px;font-weight: bold;text-align: center;\"><span style=\"border-bottom-width: 2px;border-bottom-style: solid;border-bottom-color: rgb(216, 156, 246);\">\u5f02\u6b65\u975e\u963b\u585e\u7684\u7f16\u7a0b\u65b9\u5f0f AIO (Asynchronous IO)<\/span><\/h3>\n<p style=\"padding-top: 8px;padding-bottom: 8px;line-height: 26px;margin-top: 10px;margin-bottom: 10px;font-size: 14px;word-spacing: 2px;\">\u5f53\u8fdb\u884c\u8bfb\u5199\u64cd\u4f5c\u65f6\uff0c\u53ea\u987b\u76f4\u63a5\u8c03\u7528API\u7684read\u6216write\u65b9\u6cd5\u5373\u53ef\u3002\u8fd9\u4e24\u79cd\u65b9\u6cd5\u5747\u4e3a\u5f02\u6b65\u7684\uff0c\u5bf9\u4e8e\u8bfb\u64cd\u4f5c\u800c\u8a00\uff0c\u5f53\u6709\u6d41\u53ef\u8bfb\u53d6\u65f6\uff0c\u64cd\u4f5c\u7cfb\u7edf\u4f1a\u5c06\u53ef\u8bfb\u7684\u6d41\u4f20\u5165read\u65b9\u6cd5\u7684\u7f13\u51b2\u533a\uff0c\u5e76\u901a\u77e5\u5e94\u7528\u7a0b\u5e8f\uff1b\u5bf9\u4e8e\u5199\u64cd\u4f5c\u800c\u8a00\uff0c\u5f53\u64cd\u4f5c\u7cfb\u7edf\u5c06write\u65b9\u6cd5\u4f20\u9012\u7684\u6d41\u5199\u5165\u5b8c\u6bd5\u65f6\uff0c\u64cd\u4f5c\u7cfb\u7edf\u4e3b\u52a8\u901a\u77e5\u5e94\u7528\u7a0b\u5e8f\u3002\u5373\u53ef\u4ee5\u7406\u89e3\u4e3a\uff0cread\/write\u65b9\u6cd5\u90fd\u662f\u5f02\u6b65\u7684\uff0c\u5b8c\u6210\u540e\u4f1a\u4e3b\u52a8\u8c03\u7528\u56de\u8c03\u51fd\u6570\u3002<\/p>\n<p style=\"padding-top: 8px;padding-bottom: 8px;line-height: 26px;margin-top: 10px;margin-bottom: 10px;font-size: 14px;word-spacing: 2px;\">\u5728JDK1.7\u4e2d\uff0c\u8fd9\u90e8\u5206\u5185\u5bb9\u88ab\u79f0\u4f5cNIO.2\uff0c\u4e3b\u8981\u5728java.nio.channels\u5305\u4e0b\u589e\u52a0\u4e86\u4e0b\u9762\u56db\u4e2a\u5f02\u6b65\u901a\u9053\uff1a<code style=\"word-wrap: break-word;padding: 2px 4px;border-top-left-radius: 4px;border-top-right-radius: 4px;border-bottom-right-radius: 4px;border-bottom-left-radius: 4px;margin-right: 2px;margin-left: 2px;font-family: &quot;Operator Mono&quot;, Consolas, Monaco, Menlo, monospace;word-break: break-all;color: rgb(145, 109, 213);background-image: none;\">AsynchronousSocketChannel\u3001AsynchronousServerSocketChannel\u3001AsynchronousFileChannel\u3001AsynchronousDatagramChannel<\/code><\/p>\n<p style=\"padding-top: 8px;padding-bottom: 8px;line-height: 26px;margin-top: 10px;margin-bottom: 10px;font-size: 14px;word-spacing: 2px;\"><code style=\"word-wrap: break-word;padding: 2px 4px;border-top-left-radius: 4px;border-top-right-radius: 4px;border-bottom-right-radius: 4px;border-bottom-left-radius: 4px;margin-right: 2px;margin-left: 2px;font-family: &quot;Operator Mono&quot;, Consolas, Monaco, Menlo, monospace;word-break: break-all;color: rgb(145, 109, 213);background-image: none;\">nodejs<\/code>\u5b83\u5c31\u662f\u4f7f\u7528\u8fd9\u79cd\u6a21\u5f0f\uff0c\u65e2\u7136\u804a\u5230\uff0c\u5c31\u7b80\u5355\u8bb2\u8bb2\uff0c\u5b83\u4e0d\u662f\u672c\u8282\u4e3b\u8981\u5185\u5bb9<\/p>\n<p style=\"padding-top: 8px;padding-bottom: 8px;line-height: 26px;margin-top: 10px;margin-bottom: 10px;font-size: 14px;word-spacing: 2px;\">\u5b83\u5462\uff0c\u5728\u4e3b\u7ebf\u7a0b\u91cc\u7ef4\u62a4\u4e86\u4e00\u4e2a\u4e8b\u4ef6\u961f\u5217\uff0c\u5f53\u63a5\u5230\u8bf7\u6c42\u540e\uff0c\u5c31\u5c06\u8be5\u8bf7\u6c42\u4f5c\u4e3a\u4e00\u4e2a\u4e8b\u4ef6\u653e\u5165\u8fd9\u4e2a\u961f\u5217\u4e2d\uff0c\u7136\u540e\u7ee7\u7eed\u63a5\u6536\u5176\u4ed6\u8bf7\u6c42\u3002\u5f53\u4e3b\u7ebf\u7a0b\u7a7a\u95f2\u65f6(\u6ca1\u6709\u8bf7\u6c42\u63a5\u5165\u65f6)\uff0c\u5c31\u5f00\u59cb\u5faa\u73af\u4e8b\u4ef6\u961f\u5217\uff0c\u68c0\u67e5\u961f\u5217\u4e2d\u662f\u5426\u6709\u8981\u5904\u7406\u7684\u4e8b\u4ef6\uff0c\u8fd9\u65f6\u8981\u5206\u4e24\u79cd\u60c5\u51b5\uff1a\u5982\u679c\u662f\u975e I\/O \u4efb\u52a1\uff0c\u5c31\u901a\u8fc7\u4e3b\u7ebf\u7a0b\u5904\u7406\uff0c\u5e76\u901a\u8fc7\u56de\u8c03\u51fd\u6570\u8fd4\u56de\u5230\u4e0a\u5c42\u8c03\u7528\uff1b\u5982\u679c\u662f I\/O \u4efb\u52a1\uff0c\u5c31\u4ece \u7ebf\u7a0b\u6c60 \u4e2d\u62ff\u51fa\u4e00\u4e2a\u7ebf\u7a0b\u6765\u5904\u7406\u8fd9\u4e2a\u4e8b\u4ef6\uff0c\u5e76\u901a\u8fc7\u89c2\u5bdf\u8005\u6307\u5b9a\u56de\u8c03\u51fd\u6570\uff0c\u7136\u540e\u7ee7\u7eed\u5faa\u73af\u961f\u5217\u4e2d\u7684\u5176\u4ed6\u4e8b\u4ef6\u3002\u5f53\u7ebf\u7a0b\u4e2d\u7684 I\/O \u4efb\u52a1\u5b8c\u6210\u4ee5\u540e\uff0c\u901a\u8fc7\u89c2\u5bdf\u8005\u6267\u884c\u6307\u5b9a\u7684\u56de\u8c03\u51fd\u6570\uff0c\u5e76\u628a\u8fd9\u4e2a\u5b8c\u6210\u7684\u4e8b\u4ef6\u653e\u5230\u4e8b\u4ef6\u961f\u5217\u7684\u5c3e\u90e8\uff0c\u7b49\u5f85\u4e8b\u4ef6\u5faa\u73af\uff0c\u5f53\u4e3b\u7ebf\u7a0b\u518d\u6b21\u5faa\u73af\u5230\u8be5\u4e8b\u4ef6\u65f6\uff0c\u5c31\u76f4\u63a5\u5904\u7406\u5e76\u8fd4\u56de\u7ed9\u4e0a\u5c42\u8c03\u7528<\/p>\n<h3 style=\"margin-top: 30px;margin-bottom: 15px;font-weight: bold;text-align: center;\"><span style=\"border-bottom-width: 2px;border-bottom-style: solid;border-bottom-color: rgb(216, 156, 246);\">\u540c\u6b65\u975e\u963b\u585e\u7684\u7f16\u7a0b\u65b9\u5f0f NIO (Unblocking IO)<\/span><\/h3>\n<p style=\"padding-top: 8px;padding-bottom: 8px;line-height: 26px;margin-top: 10px;margin-bottom: 10px;font-size: 14px;word-spacing: 2px;\">\u7ec8\u4e8e\u5230\u6211\u4eec\u91cd\u70b9\u5173\u6ce8\u7684\u5bf9\u8c61\u4e86, \u968f\u7740\u6211\u4eec\u4e1a\u52a1\u7684\u4e0d\u65ad\u6269\u5f20\uff0c\u7a0b\u5e8f\u540c\u6837\u4e5f\u8fce\u6765\u4e86\u5de8\u5927\u7684\u6311\u6218\uff0c\u5404\u79cd\u9ad8\u5e76\u53d1\u7684\u573a\u666f\u4e5f\u968f\u4e4b\u800c\u6765, \u6240\u4ee5\u5f88\u591a\u6280\u672f\u7684\u51fa\u73b0\u90fd\u662f\u6709\u5b83\u5b58\u5728\u7684\u9053\u7406\u7684\uff0c\u672c\u8282\u53ef\u80fd\u6709\u70b9\u96be\u61c2\uff0c\u6211\u4eec\u672c\u8282\u7684\u4efb\u52a1\u5c31\u662f\u8981\u52a8\u624b\u5b9e\u73b0\u4e00\u4e2a&nbsp;<code style=\"word-wrap: break-word;padding: 2px 4px;border-top-left-radius: 4px;border-top-right-radius: 4px;border-bottom-right-radius: 4px;border-bottom-left-radius: 4px;margin-right: 2px;margin-left: 2px;font-family: &quot;Operator Mono&quot;, Consolas, Monaco, Menlo, monospace;word-break: break-all;color: rgb(145, 109, 213);background-image: none;\">NIO<\/code>\uff0c\u8010\u5fc3\u770b\u5b8c\u54e6 ~<\/p>\n<p style=\"padding-top: 8px;padding-bottom: 8px;line-height: 26px;margin-top: 10px;margin-bottom: 10px;font-size: 14px;word-spacing: 2px;\">NIO\u672c\u8eab\u662f\u57fa\u4e8e\u4e8b\u4ef6\u9a71\u52a8\u601d\u60f3\u6765\u5b8c\u6210\u7684\uff0c\u5176\u4e3b\u8981\u60f3\u89e3\u51b3\u7684\u662f<code style=\"word-wrap: break-word;padding: 2px 4px;border-top-left-radius: 4px;border-top-right-radius: 4px;border-bottom-right-radius: 4px;border-bottom-left-radius: 4px;margin-right: 2px;margin-left: 2px;font-family: &quot;Operator Mono&quot;, Consolas, Monaco, Menlo, monospace;word-break: break-all;color: rgb(145, 109, 213);background-image: none;\">BIO<\/code>\u7684\u5927\u5e76\u53d1\u95ee\u9898\uff0c<code style=\"word-wrap: break-word;padding: 2px 4px;border-top-left-radius: 4px;border-top-right-radius: 4px;border-bottom-right-radius: 4px;border-bottom-left-radius: 4px;margin-right: 2px;margin-left: 2px;font-family: &quot;Operator Mono&quot;, Consolas, Monaco, Menlo, monospace;word-break: break-all;color: rgb(145, 109, 213);background-image: none;\">NIO<\/code>\u57fa\u4e8e<code style=\"word-wrap: break-word;padding: 2px 4px;border-top-left-radius: 4px;border-top-right-radius: 4px;border-bottom-right-radius: 4px;border-bottom-left-radius: 4px;margin-right: 2px;margin-left: 2px;font-family: &quot;Operator Mono&quot;, Consolas, Monaco, Menlo, monospace;word-break: break-all;color: rgb(145, 109, 213);background-image: none;\">Reactor<\/code>\uff0c\u5f53<code style=\"word-wrap: break-word;padding: 2px 4px;border-top-left-radius: 4px;border-top-right-radius: 4px;border-bottom-right-radius: 4px;border-bottom-left-radius: 4px;margin-right: 2px;margin-left: 2px;font-family: &quot;Operator Mono&quot;, Consolas, Monaco, Menlo, monospace;word-break: break-all;color: rgb(145, 109, 213);background-image: none;\">socket<\/code>\u6709\u6d41\u53ef\u8bfb\u6216\u53ef\u5199\u5165socket\u65f6\uff0c\u64cd\u4f5c\u7cfb\u7edf\u4f1a\u76f8\u5e94\u7684\u901a\u77e5\u5f15\u7528\u7a0b\u5e8f\u8fdb\u884c\u5904\u7406\uff0c\u5e94\u7528\u518d\u5c06\u6d41\u8bfb\u53d6\u5230\u7f13\u51b2\u533a\u6216\u5199\u5165\u64cd\u4f5c\u7cfb\u7edf\u3002\u4e5f\u5c31\u662f\u8bf4\uff0c\u8fd9\u4e2a\u65f6\u5019\uff0c\u5df2\u7ecf\u4e0d\u662f\u4e00\u4e2a\u8fde\u63a5\u5c31\u8981\u5bf9\u5e94\u4e00\u4e2a\u5904\u7406\u7ebf\u7a0b\u4e86\uff0c\u800c\u662f\u6709\u6548\u7684\u8bf7\u6c42\uff0c\u5bf9\u5e94\u4e00\u4e2a\u7ebf\u7a0b\uff0c\u5f53\u8fde\u63a5\u6ca1\u6709\u6570\u636e\u65f6\uff0c\u662f\u6ca1\u6709\u5de5\u4f5c\u7ebf\u7a0b\u6765\u5904\u7406\u7684\u3002\u5f3a\u5927\u7684\u901a\u4fe1\u6846\u67b6&nbsp;<code style=\"word-wrap: break-word;padding: 2px 4px;border-top-left-radius: 4px;border-top-right-radius: 4px;border-bottom-right-radius: 4px;border-bottom-left-radius: 4px;margin-right: 2px;margin-left: 2px;font-family: &quot;Operator Mono&quot;, Consolas, Monaco, Menlo, monospace;word-break: break-all;color: rgb(145, 109, 213);background-image: none;\">netty<\/code>\u5c31\u662f\u57fa\u4e8e\u5b83<\/p>\n<p style=\"padding-top: 8px;padding-bottom: 8px;line-height: 26px;margin-top: 10px;margin-bottom: 10px;font-size: 14px;word-spacing: 2px;\">\u540c\u6837\u7684\uff0c\u6211\u4eec\u7406\u89e3\u5b8c\u57fa\u672c\u6982\u5ff5\u540e\uff0c\u5148\u8865\u5145\u4e00\u4e0b\u524d\u7f6e\u77e5\u8bc6, \u6211\u4eec\u5148\u804a\u4e0b&nbsp;<code style=\"word-wrap: break-word;padding: 2px 4px;border-top-left-radius: 4px;border-top-right-radius: 4px;border-bottom-right-radius: 4px;border-bottom-left-radius: 4px;margin-right: 2px;margin-left: 2px;font-family: &quot;Operator Mono&quot;, Consolas, Monaco, Menlo, monospace;word-break: break-all;color: rgb(145, 109, 213);background-image: none;\">\u6d41\u4e0e\u5757<\/code><\/p>\n<h4 style=\"margin-top: 30px;margin-bottom: 15px;font-weight: bold;font-size: 18px;\">\u6d41\u4e0e\u5757<\/h4>\n<p style=\"padding-top: 8px;padding-bottom: 8px;line-height: 26px;margin-top: 10px;margin-bottom: 10px;font-size: 14px;word-spacing: 2px;\"><code style=\"word-wrap: break-word;padding: 2px 4px;border-top-left-radius: 4px;border-top-right-radius: 4px;border-bottom-right-radius: 4px;border-bottom-left-radius: 4px;margin-right: 2px;margin-left: 2px;font-family: &quot;Operator Mono&quot;, Consolas, Monaco, Menlo, monospace;word-break: break-all;color: rgb(145, 109, 213);background-image: none;\">I\/O<\/code>&nbsp;\u4e0e&nbsp;<code style=\"word-wrap: break-word;padding: 2px 4px;border-top-left-radius: 4px;border-top-right-radius: 4px;border-bottom-right-radius: 4px;border-bottom-left-radius: 4px;margin-right: 2px;margin-left: 2px;font-family: &quot;Operator Mono&quot;, Consolas, Monaco, Menlo, monospace;word-break: break-all;color: rgb(145, 109, 213);background-image: none;\">NIO<\/code>&nbsp;\u6700\u91cd\u8981\u7684\u533a\u522b\u662f\u6570\u636e\u6253\u5305\u548c\u4f20\u8f93\u7684\u65b9\u5f0f\uff0c<code style=\"word-wrap: break-word;padding: 2px 4px;border-top-left-radius: 4px;border-top-right-radius: 4px;border-bottom-right-radius: 4px;border-bottom-left-radius: 4px;margin-right: 2px;margin-left: 2px;font-family: &quot;Operator Mono&quot;, Consolas, Monaco, Menlo, monospace;word-break: break-all;color: rgb(145, 109, 213);background-image: none;\">I\/O<\/code>&nbsp;\u4ee5\u6d41\u7684\u65b9\u5f0f\u5904\u7406\u6570\u636e\uff0c\u800c&nbsp;<code style=\"word-wrap: break-word;padding: 2px 4px;border-top-left-radius: 4px;border-top-right-radius: 4px;border-bottom-right-radius: 4px;border-bottom-left-radius: 4px;margin-right: 2px;margin-left: 2px;font-family: &quot;Operator Mono&quot;, Consolas, Monaco, Menlo, monospace;word-break: break-all;color: rgb(145, 109, 213);background-image: none;\">NIO<\/code>&nbsp;\u4ee5\u5757\u7684\u65b9\u5f0f\u5904\u7406\u6570\u636e\u3002<\/p>\n<ul style=\"margin-top: 8px;margin-bottom: 8px;padding-left: 25px;font-size: 15px;list-style-type: circle;\" class=\"list-paddingleft-2\">\n<li>\n<section style=\"margin-top: 5px;margin-bottom: 5px;line-height: 26px;color: rgb(1, 1, 1);font-size: 14px;\">\n<p style=\"padding-top: 8px;padding-bottom: 8px;line-height: 26px;color: black;margin-top: 10px;margin-bottom: 10px;word-spacing: 2px;\">\u9762\u5411\u6d41\u7684 I\/O \u4e00\u6b21\u5904\u7406\u4e00\u4e2a\u5b57\u8282\u6570\u636e\uff1a\u4e00\u4e2a\u8f93\u5165\u6d41\u4ea7\u751f\u4e00\u4e2a\u5b57\u8282\u6570\u636e\uff0c\u4e00\u4e2a\u8f93\u51fa\u6d41\u6d88\u8d39\u4e00\u4e2a\u5b57\u8282\u6570\u636e\u3002\u4e3a\u6d41\u5f0f\u6570\u636e\u521b\u5efa\u8fc7\u6ee4\u5668\u975e\u5e38\u5bb9\u6613\uff0c\u94fe\u63a5\u51e0\u4e2a\u8fc7\u6ee4\u5668\uff0c\u4ee5\u4fbf\u6bcf\u4e2a\u8fc7\u6ee4\u5668\u53ea\u8d1f\u8d23\u590d\u6742\u5904\u7406\u673a\u5236\u7684\u4e00\u90e8\u5206\u3002\u4e0d\u5229\u7684\u4e00\u9762\u662f\uff0c\u9762\u5411\u6d41\u7684 I\/O \u901a\u5e38\u76f8\u5f53\u6162<\/p>\n<\/section>\n<\/li>\n<li>\n<section style=\"margin-top: 5px;margin-bottom: 5px;line-height: 26px;color: rgb(1, 1, 1);font-size: 14px;\">\n<p style=\"padding-top: 8px;padding-bottom: 8px;line-height: 26px;color: black;margin-top: 10px;margin-bottom: 10px;word-spacing: 2px;\">\u9762\u5411\u5757\u7684 I\/O \u4e00\u6b21\u5904\u7406\u4e00\u4e2a\u6570\u636e\u5757\uff0c\u6309\u5757\u5904\u7406\u6570\u636e\u6bd4\u6309\u6d41\u5904\u7406\u6570\u636e\u8981\u5feb\u5f97\u591a\u3002\u4f46\u662f\u9762\u5411\u5757\u7684 I\/O \u7f3a\u5c11\u4e00\u4e9b\u9762\u5411\u6d41\u7684 I\/O \u6240\u5177\u6709\u7684\u4f18\u96c5\u6027\u548c\u7b80\u5355\u6027\u3002<\/p>\n<\/section>\n<\/li>\n<\/ul>\n<p style=\"padding-top: 8px;padding-bottom: 8px;line-height: 26px;margin-top: 10px;margin-bottom: 10px;font-size: 14px;word-spacing: 2px;\"><code style=\"word-wrap: break-word;padding: 2px 4px;border-top-left-radius: 4px;border-top-right-radius: 4px;border-bottom-right-radius: 4px;border-bottom-left-radius: 4px;margin-right: 2px;margin-left: 2px;font-family: &quot;Operator Mono&quot;, Consolas, Monaco, Menlo, monospace;word-break: break-all;color: rgb(145, 109, 213);background-image: none;\">NIO<\/code>&nbsp;\u4e3b\u8981\u662f\u9762\u5411\u5757\u7684\u7ed3\u6784<\/p>\n<h4 style=\"margin-top: 30px;margin-bottom: 15px;font-weight: bold;font-size: 18px;\">\u901a\u9053 channel<\/h4>\n<p style=\"padding-top: 8px;padding-bottom: 8px;line-height: 26px;margin-top: 10px;margin-bottom: 10px;font-size: 14px;word-spacing: 2px;\">\u901a\u9053 Channel \u662f\u5bf9\u539f I\/O \u5305\u4e2d\u7684\u6d41\u7684\u6a21\u62df\uff0c\u53ef\u4ee5\u901a\u8fc7\u5b83\u8bfb\u53d6\u548c\u5199\u5165\u6570\u636e\u3002\u901a\u9053\u4e0e\u6d41\u7684\u4e0d\u540c\u4e4b\u5904\u5728\u4e8e\uff0c\u6d41\u53ea\u80fd\u5728\u4e00\u4e2a\u65b9\u5411\u4e0a\u79fb\u52a8(\u4e00\u4e2a\u6d41\u5fc5\u987b\u662f InputStream \u6216\u8005 OutputStream \u7684\u5b50\u7c7b)\uff0c\u800c\u901a\u9053\u662f\u53cc\u5411\u7684\uff0c\u53ef\u4ee5\u7528\u4e8e\u8bfb\u3001\u5199\u6216\u8005\u540c\u65f6\u7528\u4e8e\u8bfb\u5199\u3002\u901a\u9053\u5305\u62ec\u4ee5\u4e0b\u7c7b\u578b\uff1a<\/p>\n<ul style=\"margin-top: 8px;margin-bottom: 8px;padding-left: 25px;font-size: 15px;list-style-type: circle;\" class=\"list-paddingleft-2\">\n<li>\n<section style=\"margin-top: 5px;margin-bottom: 5px;line-height: 26px;color: rgb(1, 1, 1);font-size: 14px;\">FileChannel\uff1a\u4ece\u6587\u4ef6\u4e2d\u8bfb\u5199\u6570\u636e<\/section>\n<\/li>\n<li>\n<section style=\"margin-top: 5px;margin-bottom: 5px;line-height: 26px;color: rgb(1, 1, 1);font-size: 14px;\">DatagramChannel\uff1a\u901a\u8fc7 UDP \u8bfb\u5199\u7f51\u7edc\u4e2d\u6570\u636e<\/section>\n<\/li>\n<li>\n<section style=\"margin-top: 5px;margin-bottom: 5px;line-height: 26px;color: rgb(1, 1, 1);font-size: 14px;\">SocketChannel\uff1a\u901a\u8fc7 TCP \u8bfb\u5199\u7f51\u7edc\u4e2d\u6570\u636e<\/section>\n<\/li>\n<li>\n<section style=\"margin-top: 5px;margin-bottom: 5px;line-height: 26px;color: rgb(1, 1, 1);font-size: 14px;\">ServerSocketChannel\uff1a\u53ef\u4ee5\u76d1\u542c\u65b0\u8fdb\u6765\u7684 TCP \u8fde\u63a5\uff0c\u5bf9\u6bcf\u4e00\u4e2a\u65b0\u8fdb\u6765\u7684\u8fde\u63a5\u90fd\u4f1a\u521b\u5efa\u4e00\u4e2a SocketChannel<\/section>\n<\/li>\n<\/ul>\n<h4 style=\"margin-top: 30px;margin-bottom: 15px;font-weight: bold;font-size: 18px;\">\u7f13\u51b2\u533a Buffer<\/h4>\n<p style=\"padding-top: 8px;padding-bottom: 8px;line-height: 26px;margin-top: 10px;margin-bottom: 10px;font-size: 14px;word-spacing: 2px;\">\u53d1\u9001\u7ed9\u4e00\u4e2a\u901a\u9053\u7684\u6240\u6709\u6570\u636e\u90fd\u5fc5\u987b\u9996\u5148\u653e\u5230\u7f13\u51b2\u533a\u4e2d\uff0c\u540c\u6837\u5730\uff0c\u4ece\u901a\u9053\u4e2d\u8bfb\u53d6\u7684\u4efb\u4f55\u6570\u636e\u90fd\u8981\u5148\u8bfb\u5230\u7f13\u51b2\u533a\u4e2d\u3002\u4e5f\u5c31\u662f\u8bf4\uff0c\u4e0d\u4f1a\u76f4\u63a5\u5bf9\u901a\u9053\u8fdb\u884c\u8bfb\u5199\u6570\u636e\uff0c\u800c\u662f\u8981\u5148\u7ecf\u8fc7\u7f13\u51b2\u533a\u3002\u7f13\u51b2\u533a\u5b9e\u8d28\u4e0a\u662f\u4e00\u4e2a\u6570\u7ec4\uff0c\u4f46\u5b83\u4e0d\u4ec5\u4ec5\u662f\u4e00\u4e2a\u6570\u7ec4\u3002\u7f13\u51b2\u533a\u63d0\u4f9b\u4e86\u5bf9\u6570\u636e\u7684\u7ed3\u6784\u5316\u8bbf\u95ee\uff0c\u800c\u4e14\u8fd8\u53ef\u4ee5\u8ddf\u8e2a\u7cfb\u7edf\u7684\u8bfb\/\u5199\u8fdb\u7a0b\u3002<\/p>\n<p style=\"padding-top: 8px;padding-bottom: 8px;line-height: 26px;margin-top: 10px;margin-bottom: 10px;font-size: 14px;word-spacing: 2px;\">\u7f13\u51b2\u533a\u4e3b\u8981\u5305\u62ec\u4ee5\u4e0b\u7c7b\u578b\uff1a<\/p>\n<ul style=\"margin-top: 8px;margin-bottom: 8px;padding-left: 25px;font-size: 15px;list-style-type: circle;\" class=\"list-paddingleft-2\">\n<li>\n<section style=\"margin-top: 5px;margin-bottom: 5px;line-height: 26px;color: rgb(1, 1, 1);font-size: 14px;\">ByteBuffer<\/section>\n<\/li>\n<li>\n<section style=\"margin-top: 5px;margin-bottom: 5px;line-height: 26px;color: rgb(1, 1, 1);font-size: 14px;\">CharBuffer<\/section>\n<\/li>\n<li>\n<section style=\"margin-top: 5px;margin-bottom: 5px;line-height: 26px;color: rgb(1, 1, 1);font-size: 14px;\">ShortBuffer<\/section>\n<\/li>\n<li>\n<section style=\"margin-top: 5px;margin-bottom: 5px;line-height: 26px;color: rgb(1, 1, 1);font-size: 14px;\">IntBuffer<\/section>\n<\/li>\n<li>\n<section style=\"margin-top: 5px;margin-bottom: 5px;line-height: 26px;color: rgb(1, 1, 1);font-size: 14px;\">LongBuffer<\/section>\n<\/li>\n<li>\n<section style=\"margin-top: 5px;margin-bottom: 5px;line-height: 26px;color: rgb(1, 1, 1);font-size: 14px;\">FloatBuffer<\/section>\n<\/li>\n<li>\n<section style=\"margin-top: 5px;margin-bottom: 5px;line-height: 26px;color: rgb(1, 1, 1);font-size: 14px;\">DoubleBuffer<\/section>\n<\/li>\n<\/ul>\n<p style=\"padding-top: 8px;padding-bottom: 8px;line-height: 26px;margin-top: 10px;margin-bottom: 10px;font-size: 14px;word-spacing: 2px;\">\u8fd9\u91cc\u5b9e\u73b0\u4e00\u4e2a<code style=\"word-wrap: break-word;padding: 2px 4px;border-top-left-radius: 4px;border-top-right-radius: 4px;border-bottom-right-radius: 4px;border-bottom-left-radius: 4px;margin-right: 2px;margin-left: 2px;font-family: &quot;Operator Mono&quot;, Consolas, Monaco, Menlo, monospace;word-break: break-all;color: rgb(145, 109, 213);background-image: none;\">\u6587\u4ef6\u590d\u5236<\/code>\u7684\u5c0f\u4f8b\u5b50\u6765\u76f4\u89c2\u611f\u53d7\u4e00\u4e0b\u901a\u9053\u548c\u7f13\u51b2\u533a\u7684\u6982\u5ff5<\/p>\n<pre style=\"margin-top: 10px;margin-bottom: 10px;border-top-left-radius: 5px;border-top-right-radius: 5px;border-bottom-right-radius: 5px;border-bottom-left-radius: 5px;box-shadow: rgba(0, 0, 0, 0.55) 0px 2px 10px;\"><span style=\"display: block;background-image: url('https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2023\/05\/20230528042704988.jpeg');height: 30px;width: 749px;background-size: 40px;background-color: rgb(40, 44, 52);margin-bottom: -7px;border-top-left-radius: 5px;border-top-right-radius: 5px;border-bottom-right-radius: 5px;border-bottom-left-radius: 5px;background-position: 10px 10px;background-repeat: no-repeat no-repeat;\"><\/span><code style=\"overflow-x: auto;padding: 15px 16px 16px;color: rgb(171, 178, 191);display: -webkit-box;font-family: &quot;Operator Mono&quot;, Consolas, Monaco, Menlo, monospace;font-size: 12px;background-color: rgb(40, 44, 52);border-top-left-radius: 5px;border-top-right-radius: 5px;border-bottom-right-radius: 5px;border-bottom-left-radius: 5px;\"><span style=\"color: rgb(92, 99, 112);font-style: italic;line-height: 26px;\">\/\/&nbsp;\u7b80\u5355\u793a\u4f8b-&nbsp;\u6587\u4ef6\u5feb\u901f\u590d\u5236<\/span><br  \/>&nbsp;&nbsp;<span style=\"color: rgb(92, 99, 112);font-style: italic;line-height: 26px;\">\/\/&nbsp;\u53cc\u5411<\/span><br  \/>&nbsp;&nbsp;<span style=\"line-height: 26px;\"><span style=\"color: rgb(198, 120, 221);line-height: 26px;\">public<\/span>&nbsp;<span style=\"color: rgb(198, 120, 221);line-height: 26px;\">static<\/span>&nbsp;<span style=\"color: rgb(198, 120, 221);line-height: 26px;\">void<\/span>&nbsp;<span style=\"color: rgb(97, 174, 238);line-height: 26px;\">fastCopy<\/span><span style=\"line-height: 26px;\">(String&nbsp;dst)<\/span>&nbsp;<span style=\"color: rgb(198, 120, 221);line-height: 26px;\">throws<\/span>&nbsp;IOException&nbsp;<\/span>{<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;String&nbsp;src&nbsp;=&nbsp;<span style=\"color: rgb(152, 195, 121);line-height: 26px;\">\"test\/dog.jpg\"<\/span>;<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"color: rgb(92, 99, 112);font-style: italic;line-height: 26px;\">\/\/&nbsp;\u521b\u5efa\u6587\u4ef6\u8f93\u5165\u6d41<\/span><br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;FileInputStream&nbsp;fis&nbsp;=&nbsp;<span style=\"color: rgb(198, 120, 221);line-height: 26px;\">new<\/span>&nbsp;FileInputStream(src);<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"color: rgb(92, 99, 112);font-style: italic;line-height: 26px;\">\/\/&nbsp;\u83b7\u53d6\u8f93\u5165\u901a\u9053<\/span><br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;FileChannel&nbsp;fileInputChannel&nbsp;=&nbsp;fis.getChannel();<br  \/><br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"color: rgb(92, 99, 112);font-style: italic;line-height: 26px;\">\/\/&nbsp;\u521b\u5efa\u6587\u4ef6\u8f93\u51fa\u6d41<\/span><br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;FileOutputStream&nbsp;fos&nbsp;=&nbsp;<span style=\"color: rgb(198, 120, 221);line-height: 26px;\">new<\/span>&nbsp;FileOutputStream(dst);<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;FileChannel&nbsp;fileOutChannel&nbsp;=&nbsp;fos.getChannel();<br  \/><br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"color: rgb(92, 99, 112);font-style: italic;line-height: 26px;\">\/\/&nbsp;\u8bbe\u7f6e\u7f13\u51b2\u533a&nbsp;\u5206\u914d&nbsp;1024\u5b57\u8282\u5927\u5c0f\u7684\u7f13\u5b58\u533a<\/span><br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ByteBuffer&nbsp;buffer&nbsp;=&nbsp;ByteBuffer.allocateDirect(<span style=\"color: rgb(209, 154, 102);line-height: 26px;\">1024<\/span>);<br  \/><br  \/><br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"color: rgb(198, 120, 221);line-height: 26px;\">while<\/span>(<span style=\"color: rgb(198, 120, 221);line-height: 26px;\">true<\/span>)&nbsp;{<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"color: rgb(92, 99, 112);font-style: italic;line-height: 26px;\">\/\/&nbsp;\u8bfb\u53d6\u6587\u4ef6<\/span><br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"color: rgb(198, 120, 221);line-height: 26px;\">int<\/span>&nbsp;r&nbsp;=&nbsp;fileInputChannel.read(buffer);<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"color: rgb(92, 99, 112);font-style: italic;line-height: 26px;\">\/\/&nbsp;-1&nbsp;\u8868\u793a&nbsp;EOF<\/span><br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"color: rgb(198, 120, 221);line-height: 26px;\">if<\/span>&nbsp;(r&nbsp;==&nbsp;-<span style=\"color: rgb(209, 154, 102);line-height: 26px;\">1<\/span>)&nbsp;{<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"color: rgb(198, 120, 221);line-height: 26px;\">break<\/span>;<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br  \/><br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"color: rgb(92, 99, 112);font-style: italic;line-height: 26px;\">\/\/&nbsp;\u5207\u6362\u901a\u9053<\/span><br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;buffer.flip();<br  \/><br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"color: rgb(92, 99, 112);font-style: italic;line-height: 26px;\">\/\/&nbsp;\u5c06buffer\u5199\u5165<\/span><br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;fileOutChannel.write(buffer);<br  \/><br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"color: rgb(92, 99, 112);font-style: italic;line-height: 26px;\">\/\/&nbsp;\u6e05\u7a7a\u7f13\u51b2\u533a&nbsp;-&nbsp;\u4ee5\u4fbf\u4e0b\u6b21\u8bfb\u5199<\/span><br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;buffer.clear();<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br  \/><br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Log.info(<span style=\"color: rgb(152, 195, 121);line-height: 26px;\">\"\u590d\u5236\u5b8c\u6bd5\"<\/span>);<br  \/>&nbsp;&nbsp;}<br  \/><\/code><\/pre>\n<h4 style=\"margin-top: 30px;margin-bottom: 15px;font-weight: bold;font-size: 18px;\">NIO \u9009\u62e9\u5668<\/h4>\n<p style=\"padding-top: 8px;padding-bottom: 8px;line-height: 26px;margin-top: 10px;margin-bottom: 10px;font-size: 14px;word-spacing: 2px;\">NIO \u5b9e\u73b0\u4e86 IO \u591a\u8def\u590d\u7528\u4e2d\u7684 Reactor \u6a21\u578b\uff0c\u4e00\u4e2a\u7ebf\u7a0b Thread \u4f7f\u7528\u4e00\u4e2a\u9009\u62e9\u5668 Selector \u901a\u8fc7\u8f6e\u8be2\u7684\u65b9\u5f0f\u53bb\u76d1\u542c\u591a\u4e2a\u901a\u9053 Channel\u4e0a\u7684\u4e8b\u4ef6\uff0c\u4ece\u800c\u8ba9\u4e00\u4e2a\u7ebf\u7a0b\u5c31\u53ef\u4ee5\u5904\u7406\u591a\u4e2a\u4e8b\u4ef6\u3002\u901a\u8fc7\u914d\u7f6e\u76d1\u542c\u7684\u901a\u9053 Channel \u4e3a\u975e\u963b\u585e\uff0c\u90a3\u4e48\u5f53 Channel \u4e0a\u7684 IO \u4e8b\u4ef6\u8fd8\u672a\u5230\u8fbe\u65f6\uff0c\u5c31\u4e0d\u4f1a\u8fdb\u5165\u963b\u585e\u72b6\u6001\u4e00\u76f4\u7b49\u5f85\uff0c\u800c\u662f\u7ee7\u7eed\u8f6e\u8be2\u5176\u5b83 Channel\uff0c\u627e\u5230 IO \u4e8b\u4ef6\u5df2\u7ecf\u5230\u8fbe\u7684 Channel \u6267\u884c\u3002<\/p>\n<p style=\"padding-top: 8px;padding-bottom: 8px;line-height: 26px;margin-top: 10px;margin-bottom: 10px;font-size: 14px;word-spacing: 2px;\">\u56e0\u4e3a\u521b\u5efa\u548c\u5207\u6362\u7ebf\u7a0b\u7684\u5f00\u9500\u5f88\u5927\uff0c\u56e0\u6b64\u4f7f\u7528\u4e00\u4e2a\u7ebf\u7a0b\u6765\u5904\u7406\u591a\u4e2a\u4e8b\u4ef6\u800c\u4e0d\u662f\u4e00\u4e2a\u7ebf\u7a0b\u5904\u7406\u4e00\u4e2a\u4e8b\u4ef6\uff0c\u5bf9\u4e8e IO \u5bc6\u96c6\u578b\u7684\u5e94\u7528\u5177\u6709\u5f88\u597d\u5730\u6027\u80fd\u3002\u5e94\u8be5\u6ce8\u610f\u7684\u662f\uff0c\u53ea\u6709\u5957\u63a5\u5b57 Channel \u624d\u80fd\u914d\u7f6e\u4e3a\u975e\u963b\u585e\uff0c\u800c FileChannel \u4e0d\u80fd\uff0c\u4e3a FileChannel \u914d\u7f6e\u975e\u963b\u585e\u4e5f\u6ca1\u6709\u610f\u4e49\u3002<\/p>\n<h3 style=\"margin-top: 30px;margin-bottom: 15px;font-weight: bold;text-align: center;\"><span style=\"border-bottom-width: 2px;border-bottom-style: solid;border-bottom-color: rgb(216, 156, 246);\">\u52a8\u624b\u5b9e\u73b0 NIO<\/span><\/h3>\n<p style=\"padding-top: 8px;padding-bottom: 8px;line-height: 26px;margin-top: 10px;margin-bottom: 10px;font-size: 14px;word-spacing: 2px;\">\u597d\u4e86\uff0c\u6709\u4e86\u4e0a\u8fb9\u7684\u57fa\u672c\u6982\u5ff5\u540e\uff0c\u6211\u4eec\u6765\u5b9e\u73b0\u5c31\u6709\u4e86\u601d\u8def\u4e86~, \u540c\u6837\u7684\uff0c\u6211\u4eec\u5148\u5b9e\u73b0\u4e00\u4e2a<code style=\"word-wrap: break-word;padding: 2px 4px;border-top-left-radius: 4px;border-top-right-radius: 4px;border-bottom-right-radius: 4px;border-bottom-left-radius: 4px;margin-right: 2px;margin-left: 2px;font-family: &quot;Operator Mono&quot;, Consolas, Monaco, Menlo, monospace;word-break: break-all;color: rgb(145, 109, 213);background-image: none;\">\u5ba2\u6237\u7aef<\/code><\/p>\n<pre style=\"margin-top: 10px;margin-bottom: 10px;border-top-left-radius: 5px;border-top-right-radius: 5px;border-bottom-right-radius: 5px;border-bottom-left-radius: 5px;box-shadow: rgba(0, 0, 0, 0.55) 0px 2px 10px;\"><span style=\"display: block;background-image: url('https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2023\/05\/20230528042704988.jpeg');height: 30px;width: 749px;background-size: 40px;background-color: rgb(40, 44, 52);margin-bottom: -7px;border-top-left-radius: 5px;border-top-right-radius: 5px;border-bottom-right-radius: 5px;border-bottom-left-radius: 5px;background-position: 10px 10px;background-repeat: no-repeat no-repeat;\"><\/span><code style=\"overflow-x: auto;padding: 15px 16px 16px;color: rgb(171, 178, 191);display: -webkit-box;font-family: &quot;Operator Mono&quot;, Consolas, Monaco, Menlo, monospace;font-size: 12px;background-color: rgb(40, 44, 52);border-top-left-radius: 5px;border-top-right-radius: 5px;border-bottom-right-radius: 5px;border-bottom-left-radius: 5px;\"><span style=\"color: rgb(92, 99, 112);font-style: italic;line-height: 26px;\">\/\/&nbsp;\u5ba2\u6237\u7aef<\/span><br  \/><span style=\"color: rgb(92, 99, 112);font-style: italic;line-height: 26px;\">\/\/&nbsp;\u5ba2\u6237\u7aef\u4e3b\u8981\u5c31\u662fsocket\uff0c&nbsp;nio\u4e3b\u8981\u7528\u4e8e\u670d\u52a1\u7aef\u7684\u4e00\u79cd\u901a\u4fe1\u6a21\u5f0f<\/span><br  \/>&nbsp;&nbsp;<span style=\"line-height: 26px;\"><span style=\"color: rgb(198, 120, 221);line-height: 26px;\">public<\/span>&nbsp;<span style=\"color: rgb(198, 120, 221);line-height: 26px;\">static<\/span>&nbsp;<span style=\"color: rgb(198, 120, 221);line-height: 26px;\">void<\/span>&nbsp;<span style=\"color: rgb(97, 174, 238);line-height: 26px;\">nioClient<\/span><span style=\"line-height: 26px;\">()<\/span>&nbsp;<span style=\"color: rgb(198, 120, 221);line-height: 26px;\">throws<\/span>&nbsp;IOException,&nbsp;InterruptedException&nbsp;<\/span>{<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Socket&nbsp;socket&nbsp;=&nbsp;<span style=\"color: rgb(198, 120, 221);line-height: 26px;\">new<\/span>&nbsp;Socket(<span style=\"color: rgb(152, 195, 121);line-height: 26px;\">\"127.0.0.1\"<\/span>,&nbsp;<span style=\"color: rgb(209, 154, 102);line-height: 26px;\">8000<\/span>);<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;OutputStream&nbsp;outputStream&nbsp;=&nbsp;socket.getOutputStream();<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;DataOutputStream&nbsp;out&nbsp;=&nbsp;<span style=\"color: rgb(198, 120, 221);line-height: 26px;\">new<\/span>&nbsp;DataOutputStream(outputStream);<br  \/><br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"color: rgb(92, 99, 112);font-style: italic;line-height: 26px;\">\/\/&nbsp;\u4e3a\u4e86\u6d4b\u8bd5&nbsp;-&nbsp;\u53ea\u5199\u6570\u636e<\/span><br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"color: rgb(198, 120, 221);line-height: 26px;\">int<\/span>&nbsp;i&nbsp;=&nbsp;<span style=\"color: rgb(209, 154, 102);line-height: 26px;\">1<\/span>;<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"color: rgb(198, 120, 221);line-height: 26px;\">while<\/span>(i&nbsp;&gt;&nbsp;<span style=\"color: rgb(209, 154, 102);line-height: 26px;\">0<\/span>)&nbsp;{<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;out.writeUTF(<span style=\"color: rgb(152, 195, 121);line-height: 26px;\">\"client&nbsp;send&nbsp;num:\"<\/span>&nbsp;+&nbsp;i);<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;i&nbsp;--;<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Thread.sleep(<span style=\"color: rgb(209, 154, 102);line-height: 26px;\">3000<\/span>);<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Log.info(<span style=\"color: rgb(152, 195, 121);line-height: 26px;\">\"send&nbsp;data&nbsp;ok\"<\/span>);<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br  \/><br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;socket.close();<br  \/>&nbsp;&nbsp;}<br  \/><\/code><\/pre>\n<p style=\"padding-top: 8px;padding-bottom: 8px;line-height: 26px;margin-top: 10px;margin-bottom: 10px;font-size: 14px;word-spacing: 2px;\">\u91cd\u70b9\u5728\u670d\u52a1\u7aef:<\/p>\n<pre style=\"margin-top: 10px;margin-bottom: 10px;border-top-left-radius: 5px;border-top-right-radius: 5px;border-bottom-right-radius: 5px;border-bottom-left-radius: 5px;box-shadow: rgba(0, 0, 0, 0.55) 0px 2px 10px;\"><span style=\"display: block;background-image: url('https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2023\/05\/20230528042704988.jpeg');height: 30px;width: 749px;background-size: 40px;background-color: rgb(40, 44, 52);margin-bottom: -7px;border-top-left-radius: 5px;border-top-right-radius: 5px;border-bottom-right-radius: 5px;border-bottom-left-radius: 5px;background-position: 10px 10px;background-repeat: no-repeat no-repeat;\"><\/span><code style=\"overflow-x: auto;padding: 15px 16px 16px;color: rgb(171, 178, 191);display: -webkit-box;font-family: &quot;Operator Mono&quot;, Consolas, Monaco, Menlo, monospace;font-size: 12px;background-color: rgb(40, 44, 52);border-top-left-radius: 5px;border-top-right-radius: 5px;border-bottom-right-radius: 5px;border-bottom-left-radius: 5px;\">&nbsp;<span style=\"line-height: 26px;\"><span style=\"color: rgb(198, 120, 221);line-height: 26px;\">public<\/span>&nbsp;<span style=\"color: rgb(198, 120, 221);line-height: 26px;\">static<\/span>&nbsp;<span style=\"color: rgb(198, 120, 221);line-height: 26px;\">void<\/span>&nbsp;<span style=\"color: rgb(97, 174, 238);line-height: 26px;\">noiServer<\/span><span style=\"line-height: 26px;\">()<\/span>&nbsp;<span style=\"color: rgb(198, 120, 221);line-height: 26px;\">throws<\/span>&nbsp;IOException&nbsp;<\/span>{<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"color: rgb(92, 99, 112);font-style: italic;line-height: 26px;\">\/\/&nbsp;1.&nbsp;\u521b\u5efa\u9009\u62e9\u5668<\/span><br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Selector&nbsp;selector&nbsp;=&nbsp;Selector.open();<br  \/><br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"color: rgb(92, 99, 112);font-style: italic;line-height: 26px;\">\/\/&nbsp;2.&nbsp;\u5c06\u901a\u9053\u6ce8\u518c\u5230\u9009\u62e9\u5668\u4e0a<\/span><br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ServerSocketChannel&nbsp;serverSocketChannel&nbsp;=&nbsp;ServerSocketChannel.open();<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;serverSocketChannel.configureBlocking(<span style=\"color: rgb(198, 120, 221);line-height: 26px;\">false<\/span>);<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;serverSocketChannel.register(selector,&nbsp;SelectionKey.OP_ACCEPT);<br  \/><br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"color: rgb(92, 99, 112);font-style: italic;line-height: 26px;\">\/\/&nbsp;\u83b7\u53d6socket&nbsp;\u7ed1\u5b9a\u76d1\u542c<\/span><br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ServerSocket&nbsp;serverSocket&nbsp;=&nbsp;serverSocketChannel.socket();<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;InetSocketAddress&nbsp;address&nbsp;=&nbsp;<span style=\"color: rgb(198, 120, 221);line-height: 26px;\">new<\/span>&nbsp;InetSocketAddress(<span style=\"color: rgb(152, 195, 121);line-height: 26px;\">\"127.0.0.1\"<\/span>,&nbsp;<span style=\"color: rgb(209, 154, 102);line-height: 26px;\">8000<\/span>);<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;serverSocket.bind(address);<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Log.info(<span style=\"color: rgb(152, 195, 121);line-height: 26px;\">\"\u76d1\u542c\u6570\u636e\uff1a\"<\/span>&nbsp;+&nbsp;<span style=\"color: rgb(209, 154, 102);line-height: 26px;\">8000<\/span>);<br  \/><br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"color: rgb(92, 99, 112);font-style: italic;line-height: 26px;\">\/\/&nbsp;\u5faa\u73af\u76d1\u542c\u4e8b\u4ef6<\/span><br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"color: rgb(198, 120, 221);line-height: 26px;\">while<\/span>(<span style=\"color: rgb(198, 120, 221);line-height: 26px;\">true<\/span>)&nbsp;{<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;selector.select();<br  \/><br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Set&lt;SelectionKey&gt;&nbsp;keys&nbsp;=&nbsp;selector.selectedKeys();<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Iterator&lt;SelectionKey&gt;&nbsp;keyIterator&nbsp;=&nbsp;keys.iterator();<br  \/><br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"color: rgb(198, 120, 221);line-height: 26px;\">while<\/span>(keyIterator.hasNext())&nbsp;{<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;SelectionKey&nbsp;key&nbsp;=&nbsp;keyIterator.next();<br  \/><br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"color: rgb(198, 120, 221);line-height: 26px;\">if<\/span>(key.isAcceptable())&nbsp;{<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ServerSocketChannel&nbsp;ssChannel&nbsp;=&nbsp;(ServerSocketChannel)&nbsp;key.channel();<br  \/><br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"color: rgb(92, 99, 112);font-style: italic;line-height: 26px;\">\/\/&nbsp;\u670d\u52a1\u5668\u4e3a\u6bcf\u4e00\u4e2a\u65b0\u7684\u94fe\u63a5\u521b\u5efa\u4e00\u4e2achannel<\/span><br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;SocketChannel&nbsp;sChannel&nbsp;=&nbsp;ssChannel.accept();<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sChannel.configureBlocking(<span style=\"color: rgb(198, 120, 221);line-height: 26px;\">false<\/span>);<br  \/><br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"color: rgb(92, 99, 112);font-style: italic;line-height: 26px;\">\/\/&nbsp;\u8fd9\u4e2a\u65b0\u94fe\u63a5\u7528\u4e8e\u4ece\u5ba2\u6237\u7aef\u8bfb\u53d6\u6570\u636e&nbsp;-&nbsp;\u8bfb<\/span><br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sChannel.register(selector,&nbsp;SelectionKey.OP_READ);<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<span style=\"color: rgb(198, 120, 221);line-height: 26px;\">else<\/span>&nbsp;<span style=\"color: rgb(198, 120, 221);line-height: 26px;\">if<\/span>(key.isReadable())&nbsp;{<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"color: rgb(92, 99, 112);font-style: italic;line-height: 26px;\">\/\/&nbsp;\u83b7\u53d6\u8bfb\u4e8b\u4ef6<\/span><br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;SocketChannel&nbsp;readChannel&nbsp;=&nbsp;(SocketChannel)&nbsp;key.channel();<br  \/><br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"color: rgb(92, 99, 112);font-style: italic;line-height: 26px;\">\/**<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;\u8bfb\u53d6\u6570\u636e<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;&nbsp;1.&nbsp;\u521b\u5efa\u7f13\u51b2\u533a<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;&nbsp;2.&nbsp;\u8bfb\u53d6channel\u7684\u6570\u636e<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;&nbsp;3.&nbsp;\u8fd4\u56de\u6570\u636e<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*\/<\/span><br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ByteBuffer&nbsp;buffer&nbsp;=&nbsp;ByteBuffer.allocate(<span style=\"color: rgb(209, 154, 102);line-height: 26px;\">1024<\/span>);<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;StringBuilder&nbsp;data&nbsp;=&nbsp;<span style=\"color: rgb(198, 120, 221);line-height: 26px;\">new<\/span>&nbsp;StringBuilder();<br  \/><br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"color: rgb(92, 99, 112);font-style: italic;line-height: 26px;\">\/\/&nbsp;\u5982\u679c\u901a\u9053\u4e00\u76f4\u6709\u6570\u636e\u4ea7\u751f\uff0c&nbsp;\u5faa\u73af\u4f1a\u4e00\u76f4\u6267\u884c\uff0c&nbsp;\u76f4\u5230\u7ed3\u675f<\/span><br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"color: rgb(198, 120, 221);line-height: 26px;\">while<\/span>(<span style=\"color: rgb(198, 120, 221);line-height: 26px;\">true<\/span>)&nbsp;{<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"color: rgb(92, 99, 112);font-style: italic;line-height: 26px;\">\/\/&nbsp;\u5148\u6e05\u4e00\u4e0b\u7f13\u51b2\u533a<\/span><br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;buffer.clear();<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"color: rgb(198, 120, 221);line-height: 26px;\">int<\/span>&nbsp;cnt&nbsp;=&nbsp;readChannel.read(buffer);<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"color: rgb(198, 120, 221);line-height: 26px;\">if<\/span>(cnt&nbsp;==&nbsp;-<span style=\"color: rgb(209, 154, 102);line-height: 26px;\">1<\/span>)<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"color: rgb(198, 120, 221);line-height: 26px;\">break<\/span>;<br  \/><br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"color: rgb(92, 99, 112);font-style: italic;line-height: 26px;\">\/\/&nbsp;\u8f6c\u6362\u4e3a\u5199<\/span><br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;buffer.flip();<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"color: rgb(198, 120, 221);line-height: 26px;\">int<\/span>&nbsp;limit&nbsp;=&nbsp;buffer.limit();<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"color: rgb(198, 120, 221);line-height: 26px;\">char<\/span>[]&nbsp;chr&nbsp;=&nbsp;<span style=\"color: rgb(198, 120, 221);line-height: 26px;\">new<\/span>&nbsp;<span style=\"color: rgb(198, 120, 221);line-height: 26px;\">char<\/span>[limit];<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"color: rgb(198, 120, 221);line-height: 26px;\">for<\/span>(<span style=\"color: rgb(198, 120, 221);line-height: 26px;\">int<\/span>&nbsp;i&nbsp;=&nbsp;<span style=\"color: rgb(209, 154, 102);line-height: 26px;\">0<\/span>;i&nbsp;&lt;&nbsp;limit;&nbsp;i&nbsp;++)&nbsp;{<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;chr[i]&nbsp;=&nbsp;(<span style=\"color: rgb(198, 120, 221);line-height: 26px;\">char<\/span>)&nbsp;buffer.get(i);<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Log.info(<span style=\"color: rgb(152, 195, 121);line-height: 26px;\">\"char&nbsp;[i]&nbsp;-----&gt;&nbsp;\"<\/span>&nbsp;+&nbsp;chr[i]);<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br  \/><br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;data.append(chr);<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;buffer.clear();<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br  \/><br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"color: rgb(92, 99, 112);font-style: italic;line-height: 26px;\">\/\/\"get&nbsp;client:&nbsp;u0000\"<\/span><br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"color: rgb(92, 99, 112);font-style: italic;line-height: 26px;\">\/\/&nbsp;byte\u7a7a\u6570\u7ec4\u4e2d\u4f1a\u5305\u542b\u7a7a\u683c&nbsp;\u8fd9\u91cc\u8f6c\u5316\u4e00\u4e0b<\/span><br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;String&nbsp;res&nbsp;=&nbsp;data.toString().replaceAll(<span style=\"color: rgb(152, 195, 121);line-height: 26px;\">\"([\\u0000]*)\"<\/span>,&nbsp;<span style=\"color: rgb(152, 195, 121);line-height: 26px;\">\"\"<\/span>);<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Log.info(<span style=\"color: rgb(152, 195, 121);line-height: 26px;\">\"get&nbsp;client:&nbsp;\"<\/span>&nbsp;+&nbsp;res&nbsp;+&nbsp;<span style=\"color: rgb(152, 195, 121);line-height: 26px;\">\"n\"<\/span>);<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"color: rgb(198, 120, 221);line-height: 26px;\">if<\/span>(res.equals(<span style=\"color: rgb(152, 195, 121);line-height: 26px;\">\"get&nbsp;client:&nbsp;client&nbsp;send&nbsp;num:1\"<\/span>))&nbsp;{<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Log.info(<span style=\"color: rgb(152, 195, 121);line-height: 26px;\">\"equal\"<\/span>);&nbsp;&nbsp;<span style=\"color: rgb(92, 99, 112);font-style: italic;line-height: 26px;\">\/\/&nbsp;\"get&nbsp;client:&nbsp;u0000u0011client&nbsp;send&nbsp;num:1\"&nbsp;&nbsp;u0000&nbsp;\u8868\u793a\u7a7a\u683c<\/span><br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"color: rgb(92, 99, 112);font-style: italic;line-height: 26px;\">\/\/&nbsp;\u5173\u95ed\u901a\u9053<\/span><br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;readChannel.close();<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br  \/><br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"color: rgb(92, 99, 112);font-style: italic;line-height: 26px;\">\/\/&nbsp;\u6d88\u8d39\u5b8c\u6210\u540e\u79fb\u9664\u6389<\/span><br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;keyIterator.remove();<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br  \/>&nbsp;&nbsp;}<br  \/><\/code><\/pre>\n<p style=\"padding-top: 8px;padding-bottom: 8px;line-height: 26px;margin-top: 10px;margin-bottom: 10px;font-size: 14px;word-spacing: 2px;\">\u76f8\u5173\u6ce8\u91ca\u5462\uff0c\u90fd\u5728\u4ee3\u7801\u4f53\u73b0\u4e86\uff0c\u8fd9\u91cc\u6765\u603b\u7ed3\u4e3b\u8981\u505a\u4e86\u54ea\u4e9b\u4e8b:<\/p>\n<ul style=\"margin-top: 8px;margin-bottom: 8px;padding-left: 25px;font-size: 15px;list-style-type: circle;\" class=\"list-paddingleft-2\">\n<li>\n<section style=\"margin-top: 5px;margin-bottom: 5px;line-height: 26px;color: rgb(1, 1, 1);font-size: 14px;\">\u521b\u5efa\u9009\u62e9\u5668<\/section>\n<\/li>\n<li>\n<section style=\"margin-top: 5px;margin-bottom: 5px;line-height: 26px;color: rgb(1, 1, 1);font-size: 14px;\">\u5c06\u901a\u9053\u6ce8\u518c\u5230\u9009\u62e9\u5668\u4e0a<\/section>\n<\/li>\n<li>\n<section style=\"margin-top: 5px;margin-bottom: 5px;line-height: 26px;color: rgb(1, 1, 1);font-size: 14px;\">\u76d1\u542c\u4e8b\u4ef6<\/section>\n<\/li>\n<li>\n<section style=\"margin-top: 5px;margin-bottom: 5px;line-height: 26px;color: rgb(1, 1, 1);font-size: 14px;\">\u83b7\u53d6\u5230\u8fbe\u7684\u4e8b\u4ef6<\/section>\n<\/li>\n<li>\n<section style=\"margin-top: 5px;margin-bottom: 5px;line-height: 26px;color: rgb(1, 1, 1);font-size: 14px;\">\u4e8b\u4ef6\u5faa\u73af<\/section>\n<\/li>\n<\/ul>\n<h2 style=\"font-weight: bold;font-size: 22px;margin-top: 20px;margin-right: 10px;\"><span style=\"font-size: 18px;display: inline-block;padding-left: 10px;border-left-width: 5px;border-left-style: solid;border-left-color: rgb(145, 109, 213);\">\u7ed3\u675f\u8bed<\/span><\/h2>\n<p style=\"padding-top: 8px;padding-bottom: 8px;line-height: 26px;margin-top: 10px;margin-bottom: 10px;font-size: 14px;word-spacing: 2px;\">\u5199\u5230\u8fd9\u91cc\uff0c\u672c\u8282\u6587\u7ae0\u5c31\u5230\u6b64\u7ed3\u675f\u4e86\uff0c\u6574\u4f53\u770b\u4e0b\u6765\uff0c\u6587\u7ae0\u7bc7\u5e45\u8f83\u957f\uff0c\u5efa\u8bae\u6536\u85cf\u89c2\u770b\uff0c\u5982\u679c\u89c9\u5f97\u5199\u7684\u4e0d\u9519\uff0c\u7528\u4f60\u53d1\u8d22\u7684\u5c0f\u624b\u5e2e\u6211\u70b9\u4e2a\u8d5e\u5457 ?~<\/p>\n<figure style=\"margin-top: 10px;margin-bottom: 10px;display: flex;flex-direction: column;justify-content: center;align-items: center;\"><img decoding=\"async\" class=\"rich_pages wxw-img lazyload\" data-ratio=\"0.9890625\"  data-type=\"jpeg\" data-w=\"640\" style=\"border-top-left-radius: 6px;border-top-right-radius: 6px;border-bottom-right-radius: 6px;border-bottom-left-radius: 6px;display: block;margin: 20px auto;object-fit: contain;box-shadow: rgb(153, 153, 153) 2px 4px 7px;\" data-src=\"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2023\/05\/20230528042706627.jpeg\" src=\"https:\/\/s.nmxc.ltd\/sakurairo_vision\/@2.6\/load_svg\/inload.svg\" onerror=\"imgError(this)\"  \/><noscript><img decoding=\"async\" class=\"rich_pages wxw-img\" data-ratio=\"0.9890625\"  data-type=\"jpeg\" data-w=\"640\" style=\"border-top-left-radius: 6px;border-top-right-radius: 6px;border-bottom-right-radius: 6px;border-bottom-left-radius: 6px;display: block;margin: 20px auto;object-fit: contain;box-shadow: rgb(153, 153, 153) 2px 4px 7px;\" src=\"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2023\/05\/20230528042706627.jpeg\"  \/><\/noscript><figcaption style=\"margin-top: 5px;text-align: center;color: rgb(136, 136, 136);font-size: 13px;\">\u591a\u559d\u70ed\u6c34<\/figcaption><\/figure>\n<p style=\"padding-top: 8px;padding-bottom: 8px;line-height: 26px;margin-top: 10px;margin-bottom: 10px;font-size: 14px;word-spacing: 2px;\">\u540c\u65f6\u7ed9\u5927\u5bb6\u4e00\u4e2a\u6bd4\u8f83\u4e2d\u80af\u7684\u5efa\u8bae\uff0c\u5e73\u65f6\u5b66\u4e60\u7684\u65f6\u5019\u4e00\u5b9a\u8981\u505a\u7b14\u8bb0\uff0c\u6700\u7ec8\u8981\u7684\u662f\u8981\u53bb\u603b\u7ed3\u5b83\uff0c\u5f62\u6210\u81ea\u5df1\u7684\u77e5\u8bc6\u4f53\u7cfb\uff0c\u52a0\u5927\u81ea\u5df1\u5bf9\u77e5\u8bc6\u70b9\u7684\u7406\u89e3\uff0c\u4e0d\u65ad\u7684\u4e30\u5bcc\u81ea\u5df1\uff0c\u79ef\u7d2f\u81ea\u5df1\uff0c \u5728\u9879\u76ee\u4e2d\u53bb\u5e94\u7528\uff0c\u4e0d\u65ad\u7684\u8e29\u5751\uff0c \u8fd9\u6837\u77e5\u8bc6\u624d\u662f\u4f60\u7684~<\/p>\n<p style=\"padding-top: 8px;padding-bottom: 8px;line-height: 26px;margin-top: 10px;margin-bottom: 10px;font-size: 14px;word-spacing: 2px;\">::: tip \u5173\u6ce8\u6211 \u6bcf\u5929\u5b66\u4e60\u7f16\u7a0b\u77e5\u8bc6 , \u9996\u53d1<strong style=\"color: rgb(145, 109, 213);\">\u300c\u516c\u4f17\u53f7[\u7a0b\u5e8f\u5458\u76ae\u5361\u79cb]\u300d<\/strong>, \u56de\u590d\uff1a<strong style=\"color: rgb(145, 109, 213);\">\u300c\u516b\u80a1\u6587\u300d<\/strong>&nbsp;, \u9886\u53d6\u8fd13\u4e07\u9053 JAVA\u5927\u5382\u6587\u9762\u8bd5\u9898 ~ \u6301\u7eed\u66f4\u65b0\uff0c \u4e2a\u4eba&nbsp;\u535a\u5ba2&nbsp;:::<\/p>\n<p><\/readmore><\/section>\n<section class=\"mp_profile_iframe_wrp\"><mpprofile class=\"js_uneditable custom_select_card mp_profile_iframe\" data-pluginname=\"mpprofile\" data-id=\"MzU4NDcxOTM3OQ==\" data-headimg=\"http:\/\/mmbiz.qpic.cn\/mmbiz_png\/dDva6rRBQ2CdNqsbX0ZOtVheUHGoTtib0icQ7L0cw9gRuTRGBLBN8vicep6dA8aLicWomyRCSTIZQx51icvaYhg6EHg\/0?wx_fmt=png\" data-nickname=\"\u7a0b\u5e8f\u5458\u76ae\u5361\u79cb\" data-alias=\"weqdnj\" data-signature=\"\u5206\u4eab\u66f4\u591a\u597d\u73a9\u6709\u8da3\u7684\u7f16\u7a0b\u77e5\u8bc6~\" data-from=\"0\"><\/mpprofile><\/section>\n<blockquote>\n<p>\u672c\u7bc7\u6587\u7ae0\u6765\u6e90\u4e8e\u5fae\u4fe1\u516c\u4f17\u53f7:                 \u7a0b\u5e8f\u5458\u76ae\u5361\u79cb              <\/p>\n<\/blockquote>\n<\/div>\n","raw":"","protected":false},"excerpt":{"rendered":"<p>Java IO\u7c7b \u524d\u8a00 \u5927\u5bb6\u597d\uff0c\u4e00\u76f4\u4ee5\u6765\u6211\u90fd\u672c\u7740 \u7528\u6700\u901a\u4fd7\u7684\u8bdd\u7406\u89e3\u6838\u5fc3\u7684\u77e5\u8bc6\u70b9\uff0c \u6211\u8ba4\u4e3a\u6240\u6709\u7684\u96be\u70b9\u90fd\u79bb\u4e0d\u5f00&nbsp;\u300c\u57fa\u7840\u77e5\u8bc6\u300d &#8230;<\/p>\n","protected":false},"author":1,"featured_media":1399,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"emotion":"","emotion_color":"","title_style":"","license":"","footnotes":""},"categories":[2],"tags":[],"class_list":["post-1401","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-java"],"post_thumbnail_image":"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2023\/05\/20230528042705215-150x150.jpeg","content_first_image":"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2023\/05\/20230528042706627.jpeg","post_medium_image_300":"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2023\/05\/20230528042705215-300x128.jpeg","post_thumbnail_image_624":"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2023\/05\/20230528042705215.jpeg","post_frist_image":"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2023\/05\/20230528042706627.jpeg","post_medium_image":"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2023\/05\/20230528042705215-300x128.jpeg","post_large_image":"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2023\/05\/20230528042705215.jpeg","post_full_image":"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2023\/05\/20230528042705215.jpeg","post_all_images":[{"imagesurl":"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2023\/05\/20230528042706627.jpeg","id":"image0"},{"imagesurl":"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2023\/05\/20230528042706627.jpeg","id":"image1"}],"videoAdId":"","listAd":"0","listAdId":"","listAdEvery":6,"total_comments":0,"category_name":"Java","post_date":"2023-06-27","like_count":"0","praiseWord":"\u9f13\u52b1","copyright_state":"","excitationAd":"0","rewardedVideoAdId":"","detailAdId":"","detailAd":"0","enterpriseMinapp":"0","audios":[],"postImageUrl":"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2023\/05\/20230519082947553.jpg","avatarurls":[],"related_posts":null,"pageviews":225,"next_post_id":1377,"next_post_title":"\u9001\u7ed9Go\u5f00\u53d1\u8005\u7684Java\u57fa\u7840\u6559\u7a0b","previous_post_id":1319,"previous_post_title":"\u9762\u8bd5\u5b98: \u6709\u4e86\u89e3\u8fc7CAS\u548c\u539f\u5b50\u64cd\u4f5c\u5417\uff1f\u8bf4\u8bf4\u770b","_links":{"self":[{"href":"https:\/\/xinchewhd.com.cn\/index.php\/wp-json\/wp\/v2\/posts\/1401","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/xinchewhd.com.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/xinchewhd.com.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/xinchewhd.com.cn\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/xinchewhd.com.cn\/index.php\/wp-json\/wp\/v2\/comments?post=1401"}],"version-history":[{"count":0,"href":"https:\/\/xinchewhd.com.cn\/index.php\/wp-json\/wp\/v2\/posts\/1401\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/xinchewhd.com.cn\/index.php\/wp-json\/wp\/v2\/media\/1399"}],"wp:attachment":[{"href":"https:\/\/xinchewhd.com.cn\/index.php\/wp-json\/wp\/v2\/media?parent=1401"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/xinchewhd.com.cn\/index.php\/wp-json\/wp\/v2\/categories?post=1401"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/xinchewhd.com.cn\/index.php\/wp-json\/wp\/v2\/tags?post=1401"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}