{"id":203780,"date":"2025-05-22T10:04:12","date_gmt":"2025-05-22T02:04:12","guid":{"rendered":"https:\/\/server.hk\/cnblog\/203780\/"},"modified":"2025-05-22T10:04:12","modified_gmt":"2025-05-22T02:04:12","slug":"inputstream-%e4%b8%ad-read-%e5%92%8c-readnbytes-%e7%9a%84%e5%8c%ba%e5%88%ab%ef%bc%9a%e5%ae%83%e4%bb%ac%e5%a6%82%e4%bd%95%e5%a4%84%e7%90%86%e6%96%87%e4%bb%b6%e6%9c%ab%e5%b0%be%e5%92%8c%e8%af%bb","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/203780\/","title":{"rendered":"InputStream \u4e2d read() \u548c readNBytes() \u7684\u533a\u522b\uff1a\u5b83\u4eec\u5982\u4f55\u5904\u7406\u6587\u4ef6\u672b\u5c3e\u548c\u8bfb\u53d6\u5b57\u8282\u6570\uff1f"},"content":{"rendered":"<p><b><\/b>     <\/p>\n<h1>InputStream \u4e2d read() \u548c readNBytes() \u7684\u533a\u522b\uff1a\u5b83\u4eec\u5982\u4f55\u5904\u7406\u6587\u4ef6\u672b\u5c3e\u548c\u8bfb\u53d6\u5b57\u8282\u6570\uff1f<\/h1>\n<p>\u4ece\u73b0\u5728\u5f00\u59cb\uff0c\u6211\u4eec\u8981\u52aa\u529b\u5b66\u4e60\u5566\uff01\u4eca\u5929\u6211\u7ed9\u5927\u5bb6\u5e26\u6765<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u300aInputStream \u4e2d read() \u548c readNBytes() \u7684\u533a\u522b\uff1a\u5b83\u4eec\u5982\u4f55\u5904\u7406\u6587\u4ef6\u672b\u5c3e\u548c\u8bfb\u53d6\u5b57\u8282\u6570\uff1f\u300b<\/span>\uff0c\u611f\u5174\u8da3\u7684\u670b\u53cb\u8bf7\u7ee7\u7eed\u770b\u4e0b\u53bb\u5427\uff01\u4e0b\u6587\u4e2d\u7684\u5185\u5bb9\u6211\u4eec\u4e3b\u8981\u4f1a\u6d89\u53ca\u5230<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\"><\/span>\u7b49\u7b49\u77e5\u8bc6\u70b9\uff0c\u5982\u679c\u5728\u9605\u8bfb\u672c\u6587\u8fc7\u7a0b\u4e2d\u6709\u9047\u5230\u4e0d\u6e05\u695a\u7684\u5730\u65b9\uff0c\u6b22\u8fce\u7559\u8a00\u5440\uff01\u6211\u4eec\u4e00\u8d77\u8ba8\u8bba\uff0c\u4e00\u8d77\u5b66\u4e60\uff01<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241123\/17323654136741cc6560a71.jpg\" class=\"aligncenter\"><\/p>\n<p><strong>InputStream \u4e2d read() \u548c readNBytes() \u7684\u533a\u522b<\/strong><\/p>\n<p>InputStream \u4e2d\u7684 read() \u548c readNBytes() \u65b9\u6cd5\u7528\u4e8e\u4ece\u6d41\u4e2d\u8bfb\u53d6\u5b57\u8282\u3002\u5b83\u4eec\u4e4b\u95f4\u7684\u4e3b\u8981\u533a\u522b\u5728\u4e8e\u8bfb\u53d6\u5b57\u8282\u7684\u6570\u91cf\u548c\u5904\u7406\u6587\u4ef6\u672b\u5c3e\u65f6\u8fd4\u56de\u7684\u503c\u3002<\/p>\n<p><strong>read()<\/strong><\/p>\n<ul>\n<li>\u8bfb\u53d6\u6700\u591a len \u4e2a\u5b57\u8282\u6216\u5230\u8fbe\u6d41\u7684\u672b\u5c3e\u3002<\/li>\n<li>\u8fd4\u56de\u5b9e\u9645\u8bfb\u53d6\u7684\u5b57\u8282\u6570\uff0c\u6216\u8005\u5728\u5230\u8fbe\u6d41\u7684\u672b\u5c3e\u65f6\u8fd4\u56de -1\u3002<\/li>\n<\/ul>\n<p><strong>readNBytes()<\/strong><\/p>\n<ul>\n<li>\u5c3d\u53ef\u80fd\u8bfb\u53d6 len \u4e2a\u5b57\u8282\uff0c\u76f4\u5230\u8fbe\u5230\u6d41\u7684\u672b\u5c3e\u3002<\/li>\n<li>\u8fd4\u56de\u5b9e\u9645\u8bfb\u53d6\u7684\u5b57\u8282\u6570\uff0c\u5373\u4f7f\u5230\u8fbe\u6d41\u7684\u672b\u5c3e\uff0c\u8fd4\u56de\u7684\u5b57\u8282\u6570\u4e5f\u53ef\u80fd\u5c11\u4e8e len\u3002<\/li>\n<\/ul>\n<p>\u56e0\u6b64\uff0cread() \u53ef\u80fd\u4f1a\u8bfb\u53d6\u5c11\u4e8e len \u4e2a\u5b57\u8282\uff0c\u800c readNBytes() \u59cb\u7ec8\u4f1a\u5c1d\u8bd5\u8bfb\u53d6 len \u4e2a\u5b57\u8282\u3002<\/p>\n<p>\u9664\u4e86\u6587\u672c\u672b\u5c3e\u518d\u8c03\u7528\u65f6\uff0cread() \u8fd4\u56de\u503c\u4e3a -1\uff0creadNBytes() \u8fd4\u56de\u503c\u4e3a 0 \u5916\uff0creadNBytes() \u5728\u8bfb\u53d6\u5b57\u8282\u65b9\u9762\u66f4\u52a0\u6fc0\u8fdb\uff0c\u56e0\u4e3a\u5b83\u4f1a\u5c1d\u8bd5\u5c3d\u53ef\u80fd\u591a\u5730\u8bfb\u53d6\u5b57\u8282\u3002<\/p>\n<p>\u7406\u8bba\u8981\u638c\u63e1\uff0c\u5b9e\u64cd\u4e0d\u80fd\u843d\uff01\u4ee5\u4e0a\u5173\u4e8e\u300aInputStream \u4e2d read() \u548c readNBytes() \u7684\u533a\u522b\uff1a\u5b83\u4eec\u5982\u4f55\u5904\u7406\u6587\u4ef6\u672b\u5c3e\u548c\u8bfb\u53d6\u5b57\u8282\u6570\uff1f\u300b\u7684\u8be6\u7ec6\u4ecb\u7ecd\uff0c\u5927\u5bb6\u90fd\u638c\u63e1\u4e86\u5427\uff01\u5982\u679c\u60f3\u8981\u7ee7\u7eed\u63d0\u5347\u81ea\u5df1\u7684\u80fd\u529b\uff0c\u90a3\u4e48\u5c31\u6765\u5173\u6ce8\u516c\u4f17\u53f7\u5427\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>InputStream \u4e2d re&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4925],"tags":[],"class_list":["post-203780","post","type-post","status-publish","format-standard","hentry","category-4925"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/203780","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/comments?post=203780"}],"version-history":[{"count":0,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/203780\/revisions"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=203780"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=203780"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=203780"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}