{"id":36272,"date":"2024-11-26T11:13:36","date_gmt":"2024-11-26T03:13:36","guid":{"rendered":"https:\/\/fwq.ai\/blog\/36272\/"},"modified":"2024-11-26T11:13:36","modified_gmt":"2024-11-26T03:13:36","slug":"java-inputstream-%e4%b8%ad%e7%9a%84-read-%e5%92%8c-readnbytes%ef%bc%9a%e7%a9%b6%e7%ab%9f%e6%9c%89%e4%bb%80%e4%b9%88%e5%8c%ba%e5%88%ab%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/36272\/","title":{"rendered":"Java InputStream \u4e2d\u7684 read() \u548c readNBytes()\uff1a\u7a76\u7adf\u6709\u4ec0\u4e48\u533a\u522b\uff1f"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/246\/273\/173104759329530.jpg\" class=\"aligncenter\" title=\"Java InputStream \u4e2d\u7684 read() \u548c readNBytes()\uff1a\u7a76\u7adf\u6709\u4ec0\u4e48\u533a\u522b\uff1f\u63d2\u56fe\" alt=\"Java InputStream \u4e2d\u7684 read() \u548c readNBytes()\uff1a\u7a76\u7adf\u6709\u4ec0\u4e48\u533a\u522b\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>\u4ece java \u7684 InputStream \u4e2d\u8bfb\u53d6\u6570\u636e\uff1aread() \u4e0e readNBytes() \u7684<\/strong><\/p>\n<p>java \u7684 InputStream \u63d0\u4f9b\u4e86\u4e24\u79cd\u5e38\u89c1\u65b9\u6cd5 read() \u548c readNBytes() \u6765\u8bfb\u53d6\u6570\u636e\u3002\u867d\u7136\u4e24\u8005\u90fd\u88ab\u7528\u4e8e\u4ece\u6d41\u4e2d\u8bfb\u53d6\u5b57\u8282\uff0c\u4f46\u5b83\u4eec\u6709\u4e00\u4e9b\u5173\u952e\u7684\u533a\u522b\u3002<\/p>\n<p><strong>read() \u65b9\u6cd5\uff1a<\/strong><\/p>\n<ul>\n<li>\u4e00\u6b21\u8bfb\u53d6\u6700\u591a\u6307\u5b9a\u957f\u5ea6\u7684\u5b57\u8282\u3002<\/li>\n<li>\u8fd4\u56de\u5b9e\u9645\u8bfb\u53d6\u7684\u5b57\u8282\u6570\u6216 -1\uff08\u5982\u679c\u6d41\u5df2\u7ed3\u675f\uff09\u3002<\/li>\n<li>\u8be5\u65b9\u6cd5\u5728\u6d41\u7684\u672b\u5c3e\u8c03\u7528\u65f6\uff0c\u8fd4\u56de -1\u3002<\/li>\n<\/ul>\n<p><strong>readNBytes() \u65b9\u6cd5\uff1a<\/strong><\/p>\n<p><span>\u7acb\u5373\u5b66\u4e60<\/span>\u201c\u201d\uff1b<\/p>\n<ul>\n<li>\u5c1d\u8bd5\u8bfb\u53d6\u6307\u5b9a\u957f\u5ea6\u7684\u5b57\u8282\u3002<\/li>\n<li>\u5982\u679c\u6d41\u5df2\u7ed3\u675f\uff0c\u5219\u8fd4\u56de\u5b9e\u9645\u8bfb\u53d6\u7684\u5b57\u8282\u6570\uff0c\u5f53\u6d41\u4e2d\u6ca1\u6709\u5b57\u8282\u65f6\u8fd4\u56de 0\u3002<\/li>\n<li>\u8be5\u65b9\u6cd5\u4f1a\u591a\u6b21\u8c03\u7528 read() \u76f4\u5230\u8bfb\u53d6\u5230\u6307\u5b9a\u957f\u5ea6\u7684\u5b57\u8282\u6216\u5230\u8fbe\u6d41\u7684\u672b\u5c3e\u3002<\/li>\n<\/ul>\n<p><strong>\u5173\u952e\u533a\u522b\uff1a<\/strong><\/p>\n<ul>\n<li> <strong>\u8bfb\u53d6\u7684\u5b57\u8282\u6570\uff1a<\/strong>read() \u53ef\u80fd\u4f1a\u8bfb\u53d6\u6bd4\u6307\u5b9a\u957f\u5ea6\u66f4\u5c11\u7684\u5b57\u8282\uff0c\u800c readNBytes() \u4f1a\u5c1d\u8bd5\u8bfb\u53d6\u6307\u5b9a\u957f\u5ea6\u7684\u5b57\u8282\u3002<\/li>\n<li> <strong>\u8fd4\u56de\u503c\uff1a<\/strong>read() \u8fd4\u56de\u5b9e\u9645\u8bfb\u53d6\u7684\u5b57\u8282\u6570\u6216 -1\uff0c\u800c readNBytes() \u8fd4\u56de\u5b9e\u9645\u8bfb\u53d6\u7684\u5b57\u8282\u6570\u6216 0\uff08\u5982\u679c\u6d41\u5df2\u7ed3\u675f\uff09\u3002<\/li>\n<li> <strong>\u884c\u4e3a\u4e0a\u7684\u5dee\u5f02\uff1a<\/strong>read() \u4e0d\u4f1a\u5c1d\u8bd5\u8bfb\u53d6\u6d41\u4e2d\u5269\u4f59\u7684\u6240\u6709\u5b57\u8282\uff0c\u800c readNBytes() \u4f1a\u3002<\/li>\n<\/ul>\n<p>\u603b\u4e4b\uff0creadNBytes() \u6bd4 read() \u66f4\u8d2a\u5a6a\uff0c\u56e0\u4e3a\u5b83\u4f1a\u5c1d\u8bd5\u8bfb\u53d6\u5c3d\u53ef\u80fd\u591a\u7684\u5b57\u8282\u3002readNBytes() \u7684\u5b9e\u73b0\u4e5f\u66f4\u590d\u6742\uff0c\u56e0\u4e3a\u5b83\u9700\u8981\u5728\u5185\u90e8\u5faa\u73af\u8c03\u7528 read() \u76f4\u5230\u8fbe\u5230\u6307\u5b9a\u957f\u5ea6\u6216\u6d41\u7684\u672b\u5c3e\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662fJava InputStream \u4e2d\u7684 read() \u548c readNBytes()\uff1a\u7a76\u7adf\u6709\u4ec0\u4e48\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>\u4ece java \u7684 InputStream \u4e2d\u8bfb\u53d6\u6570\u636e\uff1aread() \u4e0e readNBytes() \u7684 java \u7684 InputStream \u63d0\u4f9b\u4e86\u4e24\u79cd\u5e38\u89c1\u65b9\u6cd5 read() \u548c readNBytes() \u6765\u8bfb\u53d6\u6570\u636e\u3002\u867d\u7136\u4e24\u8005\u90fd\u88ab\u7528\u4e8e\u4ece\u6d41\u4e2d\u8bfb\u53d6\u5b57\u8282\uff0c\u4f46\u5b83\u4eec\u6709\u4e00\u4e9b\u5173\u952e\u7684\u533a\u522b\u3002 read() \u65b9\u6cd5\uff1a \u4e00\u6b21\u8bfb\u53d6\u6700\u591a\u6307\u5b9a\u957f\u5ea6\u7684\u5b57\u8282\u3002 \u8fd4\u56de\u5b9e\u9645\u8bfb\u53d6\u7684\u5b57\u8282\u6570\u6216 -1\uff08\u5982\u679c\u6d41\u5df2\u7ed3\u675f\uff09\u3002 \u8be5\u65b9\u6cd5\u5728\u6d41\u7684\u672b\u5c3e\u8c03\u7528\u65f6\uff0c\u8fd4\u56de -1\u3002 readNBytes() \u65b9\u6cd5\uff1a \u7acb\u5373\u5b66\u4e60\u201c\u201d\uff1b \u5c1d\u8bd5\u8bfb\u53d6\u6307\u5b9a\u957f\u5ea6\u7684\u5b57\u8282\u3002 \u5982\u679c\u6d41\u5df2\u7ed3\u675f\uff0c\u5219\u8fd4\u56de\u5b9e\u9645\u8bfb\u53d6\u7684\u5b57\u8282\u6570\uff0c\u5f53\u6d41\u4e2d\u6ca1\u6709\u5b57\u8282\u65f6\u8fd4\u56de 0\u3002 \u8be5\u65b9\u6cd5\u4f1a\u591a\u6b21\u8c03\u7528 read() \u76f4\u5230\u8bfb\u53d6\u5230\u6307\u5b9a\u957f\u5ea6\u7684\u5b57\u8282\u6216\u5230\u8fbe\u6d41\u7684\u672b\u5c3e\u3002 \u5173\u952e\u533a\u522b\uff1a \u8bfb\u53d6\u7684\u5b57\u8282\u6570\uff1aread() \u53ef\u80fd\u4f1a\u8bfb\u53d6\u6bd4\u6307\u5b9a\u957f\u5ea6\u66f4\u5c11\u7684\u5b57\u8282\uff0c\u800c readNBytes() \u4f1a\u5c1d\u8bd5\u8bfb\u53d6\u6307\u5b9a\u957f\u5ea6\u7684\u5b57\u8282\u3002 \u8fd4\u56de\u503c\uff1aread() \u8fd4\u56de\u5b9e\u9645\u8bfb\u53d6\u7684\u5b57\u8282\u6570\u6216 -1\uff0c\u800c readNBytes() \u8fd4\u56de\u5b9e\u9645\u8bfb\u53d6\u7684\u5b57\u8282\u6570\u6216 0\uff08\u5982\u679c\u6d41\u5df2\u7ed3\u675f\uff09\u3002 \u884c\u4e3a\u4e0a\u7684\u5dee\u5f02\uff1aread() \u4e0d\u4f1a\u5c1d\u8bd5\u8bfb\u53d6\u6d41\u4e2d\u5269\u4f59\u7684\u6240\u6709\u5b57\u8282\uff0c\u800c readNBytes() \u4f1a\u3002 \u603b\u4e4b\uff0creadNBytes() \u6bd4 read() \u66f4\u8d2a\u5a6a\uff0c\u56e0\u4e3a\u5b83\u4f1a\u5c1d\u8bd5\u8bfb\u53d6\u5c3d\u53ef\u80fd\u591a\u7684\u5b57\u8282\u3002readNBytes() \u7684\u5b9e\u73b0\u4e5f\u66f4\u590d\u6742\uff0c\u56e0\u4e3a\u5b83\u9700\u8981\u5728\u5185\u90e8\u5faa\u73af\u8c03\u7528 read() \u76f4\u5230\u8fbe\u5230\u6307\u5b9a\u957f\u5ea6\u6216\u6d41\u7684\u672b\u5c3e\u3002 \u4ee5\u4e0a\u5c31\u662fJava [&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-36272","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/36272","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=36272"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/36272\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=36272"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=36272"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=36272"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}