{"id":36286,"date":"2024-11-26T16:02:55","date_gmt":"2024-11-26T08:02:55","guid":{"rendered":"https:\/\/fwq.ai\/blog\/36286\/"},"modified":"2024-11-26T16:02:55","modified_gmt":"2024-11-26T08:02:55","slug":"java-inputstream-%e4%b8%ad-read-%e5%92%8c-readnbytes-%e7%9a%84%e5%8c%ba%e5%88%ab%ef%bc%9a%e4%bd%95%e6%97%b6%e8%af%a5%e9%80%89%e6%8b%a9%e5%93%aa%e7%a7%8d%e8%af%bb%e5%8f%96%e6%96%b9%e6%b3%95","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/36286\/","title":{"rendered":"Java InputStream \u4e2d read() \u548c readNBytes() \u7684\u533a\u522b\uff1a\u4f55\u65f6\u8be5\u9009\u62e9\u54ea\u79cd\u8bfb\u53d6\u65b9\u6cd5\uff1f"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/246\/273\/173105121157184.jpg\" class=\"aligncenter\" title=\"Java InputStream \u4e2d read() \u548c readNBytes() \u7684\u533a\u522b\uff1a\u4f55\u65f6\u8be5\u9009\u62e9\u54ea\u79cd\u8bfb\u53d6\u65b9\u6cd5\uff1f\u63d2\u56fe\" alt=\"Java InputStream \u4e2d read() \u548c readNBytes() \u7684\u533a\u522b\uff1a\u4f55\u65f6\u8be5\u9009\u62e9\u54ea\u79cd\u8bfb\u53d6\u65b9\u6cd5\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>Java \u7684 InputStream \u4e2d read() \u548c readNBytes() \u7684<\/strong><\/p>\n<p>Java \u7684 InputStream \u5177\u6709\u4e24\u4e2a\u76f8\u5173\u7684\u8bfb\u53d6\u65b9\u6cd5\uff1aread() \u548c readNBytes()\u3002\u867d\u7136\u5b83\u4eec\u90fd\u7528\u4e8e\u8bfb\u53d6\u6570\u636e\uff0c\u4f46\u5b83\u4eec\u6709\u7ec6\u5fae\u7684\u533a\u522b\u3002<\/p>\n<p><strong>read(byte[] b, int off, int len)<\/strong><\/p>\n<ul>\n<li>\u4ece\u6d41\u4e2d\u8bfb\u53d6\u6700\u591a len \u4e2a\u5b57\u8282\uff0c\u5e76\u5c06\u5b83\u4eec\u5b58\u50a8\u5728\u5b57\u8282\u6570\u7ec4 b \u7684\u504f\u79fb\u91cf off \u5f00\u59cb\u5904\u3002<\/li>\n<li>\u8fd4\u56de\u5b9e\u9645\u8bfb\u53d6\u7684\u5b57\u8282\u6570\uff08\u53ef\u80fd\u5c11\u4e8e len\uff09\u3002<\/li>\n<li>\u5982\u679c\u5728\u8bfb\u53d6\u7b2c\u4e00\u4e2a\u5b57\u8282\u65f6\u9047\u5230\u6d41\u7684\u7ed3\u5c3e\uff0c\u5219\u8fd4\u56de -1\u3002<\/li>\n<\/ul>\n<p><strong>readNBytes(byte[] b, int off, int len)<\/strong><\/p>\n<p><span>\u7acb\u5373\u5b66\u4e60<\/span>\u201c\u201d\uff1b<\/p>\n<ul>\n<li>\u5c1d\u8bd5\u8bfb\u53d6\u6070\u597d len \u4e2a\u5b57\u8282\uff0c\u5e76\u5c06\u5b83\u4eec\u5b58\u50a8\u5728\u5b57\u8282\u6570\u7ec4 b \u7684\u504f\u79fb\u91cf off \u5f00\u59cb\u5904\u3002<\/li>\n<li>\u5185\u90e8\u5faa\u73af\u8c03\u7528 read() \u65b9\u6cd5\uff0c\u76f4\u5230\u8bfb\u53d6\u5230 len \u4e2a\u5b57\u8282\u6216\u5230\u8fbe\u6d41\u7684\u7ed3\u5c3e\u3002<\/li>\n<li>\u8fd4\u56de\u5b9e\u9645\u8bfb\u53d6\u7684\u5b57\u8282\u6570\u3002\u5982\u679c\u5728\u8bfb\u53d6\u8fc7\u7a0b\u4e2d\u8fbe\u5230\u6d41\u7684\u7ed3\u5c3e\uff0c\u5219\u8fd4\u56de\u503c\u4e3a 0\u3002<\/li>\n<\/ul>\n<p><strong>\u5173\u952e\u533a\u522b<\/strong><\/p>\n<ul>\n<li> <strong>\u8bfb\u53d6\u7684<\/strong> <strong>\u5b57\u8282\u6570\uff1a<\/strong> read() \u53ef\u80fd\u4f1a\u8bfb\u53d6\u5c11\u4e8e len \u4e2a\u5b57\u8282\uff0c\u800c readNBytes() \u603b\u4f1a\u5c1d\u8bd5\u8bfb\u53d6 len \u4e2a\u5b57\u8282\u3002<\/li>\n<li> <strong>\u8fd4\u56de\u503c\uff1a<\/strong> read() \u5728\u8fbe\u5230\u6d41\u7684\u7ed3\u5c3e\u65f6\u8fd4\u56de -1\uff0c\u800c readNBytes() \u8fd4\u56de\u5b9e\u9645\u8bfb\u53d6\u7684\u5b57\u8282\u6570\uff08\u53ef\u80fd\u4e3a 0\uff09\u3002<\/li>\n<li> <strong>\u884c\u4e3a\uff1a<\/strong> readNBytes() \u6bd4 read() \u66f4\u52a0\u201c\u8d2a\u5fc3\u201d\uff0c\u5b83\u786e\u4fdd\u5c3d\u91cf\u8bfb\u53d6\u6307\u5b9a\u6570\u91cf\u7684\u5b57\u8282\u3002<\/li>\n<\/ul>\n<p>\u603b\u4e4b\uff0creadNBytes() \u63d0\u4f9b\u4e86\u4e00\u79cd\u66f4\u5065\u58ee\u7684\u65b9\u6cd5\u6765\u8bfb\u53d6\u786e\u5207\u6570\u91cf\u7684\u5b57\u8282\uff0c\u5373\u4f7f\u5728\u9700\u8981\u591a\u6b21\u8c03\u7528 read() \u7684\u60c5\u51b5\u4e0b\u3002\u800c read() \u5219\u66f4\u5bb9\u6613\u5b9e\u73b0\uff0c\u4f46\u9700\u8981\u66f4\u52a0\u6ce8\u610f\u6587\u4ef6\u7ed3\u5c3e\u3002\u9009\u62e9\u54ea\u79cd\u65b9\u6cd5\u53d6\u51b3\u4e8e\u5177\u4f53\u7684\u9700\u6c42\u548c\u6027\u80fd\u8003\u8651\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662fJava InputStream \u4e2d read() \u548c readNBytes() \u7684\uff1a\u4f55\u65f6\u8be5\u9009\u62e9\u54ea\u79cd\u8bfb\u53d6\u65b9\u6cd5\uff1f\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Java \u7684 InputStream \u4e2d read() \u548c readNBytes() \u7684 Java \u7684 InputStream \u5177\u6709\u4e24\u4e2a\u76f8\u5173\u7684\u8bfb\u53d6\u65b9\u6cd5\uff1aread() \u548c readNBytes()\u3002\u867d\u7136\u5b83\u4eec\u90fd\u7528\u4e8e\u8bfb\u53d6\u6570\u636e\uff0c\u4f46\u5b83\u4eec\u6709\u7ec6\u5fae\u7684\u533a\u522b\u3002 read(byte[] b, int off, int len) \u4ece\u6d41\u4e2d\u8bfb\u53d6\u6700\u591a len \u4e2a\u5b57\u8282\uff0c\u5e76\u5c06\u5b83\u4eec\u5b58\u50a8\u5728\u5b57\u8282\u6570\u7ec4 b \u7684\u504f\u79fb\u91cf off \u5f00\u59cb\u5904\u3002 \u8fd4\u56de\u5b9e\u9645\u8bfb\u53d6\u7684\u5b57\u8282\u6570\uff08\u53ef\u80fd\u5c11\u4e8e len\uff09\u3002 \u5982\u679c\u5728\u8bfb\u53d6\u7b2c\u4e00\u4e2a\u5b57\u8282\u65f6\u9047\u5230\u6d41\u7684\u7ed3\u5c3e\uff0c\u5219\u8fd4\u56de -1\u3002 readNBytes(byte[] b, int off, int len) \u7acb\u5373\u5b66\u4e60\u201c\u201d\uff1b \u5c1d\u8bd5\u8bfb\u53d6\u6070\u597d len \u4e2a\u5b57\u8282\uff0c\u5e76\u5c06\u5b83\u4eec\u5b58\u50a8\u5728\u5b57\u8282\u6570\u7ec4 b \u7684\u504f\u79fb\u91cf off \u5f00\u59cb\u5904\u3002 \u5185\u90e8\u5faa\u73af\u8c03\u7528 read() \u65b9\u6cd5\uff0c\u76f4\u5230\u8bfb\u53d6\u5230 len \u4e2a\u5b57\u8282\u6216\u5230\u8fbe\u6d41\u7684\u7ed3\u5c3e\u3002 \u8fd4\u56de\u5b9e\u9645\u8bfb\u53d6\u7684\u5b57\u8282\u6570\u3002\u5982\u679c\u5728\u8bfb\u53d6\u8fc7\u7a0b\u4e2d\u8fbe\u5230\u6d41\u7684\u7ed3\u5c3e\uff0c\u5219\u8fd4\u56de\u503c\u4e3a 0\u3002 \u5173\u952e\u533a\u522b \u8bfb\u53d6\u7684 \u5b57\u8282\u6570\uff1a [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-36286","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/36286","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=36286"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/36286\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=36286"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=36286"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=36286"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}