{"id":36073,"date":"2024-11-26T09:12:30","date_gmt":"2024-11-26T01:12:30","guid":{"rendered":"https:\/\/fwq.ai\/blog\/36073\/"},"modified":"2024-11-26T09:12:30","modified_gmt":"2024-11-26T01:12:30","slug":"java-%e4%b8%ad-printwriter-%e7%9a%84-write-%e5%92%8c-print-%e6%96%b9%e6%b3%95%ef%bc%9a%e6%9c%89%e5%93%aa%e4%ba%9b%e5%8c%ba%e5%88%ab%e5%92%8c%e5%ba%94%e7%94%a8%e5%9c%ba%e6%99%af%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/36073\/","title":{"rendered":"Java \u4e2d PrintWriter \u7684 write \u548c print \u65b9\u6cd5\uff1a\u6709\u54ea\u4e9b\u533a\u522b\u548c\u5e94\u7528\u573a\u666f\uff1f"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/246\/273\/173093779152708.jpg\" class=\"aligncenter\" title=\"Java \u4e2d PrintWriter \u7684 write \u548c print \u65b9\u6cd5\uff1a\u6709\u54ea\u4e9b\u533a\u522b\u548c\u5e94\u7528\u573a\u666f\uff1f\u63d2\u56fe\" alt=\"Java \u4e2d PrintWriter \u7684 write \u548c print \u65b9\u6cd5\uff1a\u6709\u54ea\u4e9b\u533a\u522b\u548c\u5e94\u7528\u573a\u666f\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>java\u4e2d\u7684printwriter\u7684write\u65b9\u6cd5\u548cprint\u65b9\u6cd5\u6bd4\u8f83<\/strong><\/p>\n<p>printwriter\u662fjava\u4e2d\u7684\u4e00\u4e2a\u5de5\u5177\u7c7b\uff0c\u7528\u4e8e\u5230\u6d41\u3002write\u548cprint\u662f\u5b83\u63d0\u4f9b\u7684\u4e24\u4e2a\u91cd\u8981\u65b9\u6cd5\uff0c\u7528\u4e8e\u5411response\u5bf9\u8c61\u5199\u5165\u5b57\u7b26\u6570\u636e\u3002<\/p>\n<p><strong>\u8be6\u89e3<\/strong><\/p>\n<p>\u867d\u7136write\u548cprint\u65b9\u6cd5\u90fd\u53ef\u5c06\u5b57\u7b26\u6570\u636e\u5199\u5165response\u5bf9\u8c61\uff0c\u4f46\u5b83\u4eec\u7684\u5b9e\u73b0\u548c\u7528\u9014\u6709\u6240\u4e0d\u540c\uff1a<\/p>\n<p><span>\u7acb\u5373\u5b66\u4e60<\/span>\u201c\u201d\uff1b<\/p>\n<ul>\n<li>\n<p><strong>write\u65b9\u6cd5\uff1a<\/strong><\/p>\n<ul>\n<li>\u5c06\u5b57\u7b26\u6570\u636e\u539f\u6837\u8f93\u51fa\uff0c\u4e0d\u6267\u884c\u4efb\u4f55\u7279\u6b8a\u5904\u7406\u3002<\/li>\n<li>\u4e3b\u8981\u7528\u4e8e\u5199\u5165\u975e\u683c\u5f0f\u5316\u6570\u636e\uff0c\u5982\u4e8c\u8fdb\u5236\u6570\u636e\u6216\u6765\u81ea\u5176\u5b83\u6d41\u7684\u6570\u636e\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>print\u65b9\u6cd5\uff1a<\/strong><\/p>\n<ul>\n<li>\u8f93\u51fa\u5b57\u7b26\u6570\u636e\u65f6\uff0c\u4f1a\u5148\u5c06\u5176\u8f6c\u6362\u4e3a\u5b57\u7b26\u4e32\u683c\u5f0f\u3002<\/li>\n<li>\u901a\u5e38\u7528\u4e8e\u5199\u5165\u683c\u5f0f\u5316\u6570\u636e\uff0c\u5982html\u6807\u7b7e\u3001\u6587\u672c\u7b49\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p><strong>\u5e94\u7528\u573a\u666f<\/strong><\/p>\n<p>\u8003\u8651\u4ee5\u4e0b\u4ee3\u7801\u793a\u4f8b\uff1a<\/p>\n<pre>PrintWriter out = response.getWriter();\nout.write(\"Hello World\"); \/\/ \u8f93\u51fa\u539f\u5b57\u7b26\u6570\u636e\nout.print(\"&lt;p&gt;Hello World&lt;\/p&gt;\"); \/\/ \u8f93\u51fa\u683c\u5f0f\u5316HTML<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u5728\u4e0a\u9762\u7684\u793a\u4f8b\u4e2d\uff0cwrite\u65b9\u6cd5\u5c06\u201chello world\u201d\u539f\u6837\u8f93\u51fa\uff0c\u800cprint\u65b9\u6cd5\u5c06\u5176\u8f6c\u6362\u4e3ahtml\u683c\u5f0f\u518d\u8f93\u51fa\u3002<\/p>\n<p><strong>\u7ed3\u8bba<\/strong><\/p>\n<p>write\u65b9\u6cd5\u662f\u4f4e\u7ea7\u8f93\u51fa\u65b9\u6cd5\uff0c\u4e3b\u8981\u7528\u4e8e\u5199\u5165\u975e\u683c\u5f0f\u5316\u6570\u636e\u3002print\u65b9\u6cd5\u662f\u9ad8\u7ea7\u8f93\u51fa\u65b9\u6cd5\uff0c\u901a\u5e38\u7528\u4e8e\u5199\u5165\u683c\u5f0f\u5316\u6570\u636e\u3002\u6839\u636e\u5177\u4f53\u9700\u6c42\uff0c\u9009\u62e9\u5408\u9002\u7684\u8f93\u51fa\u65b9\u6cd5\u53ef\u4ee5\u63d0\u5347\u4ee3\u7801\u6e05\u6670\u5ea6\u548c\u7075\u6d3b\u5ea6\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662fJava \u4e2d PrintWriter \u7684 write \u548c print \u65b9\u6cd5\uff1a\u6709\u54ea\u4e9b\u548c\u5e94\u7528\u573a\u666f\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\u4e2d\u7684printwriter\u7684write\u65b9\u6cd5\u548cprint\u65b9\u6cd5\u6bd4\u8f83 printwriter\u662fjava\u4e2d\u7684\u4e00\u4e2a\u5de5\u5177\u7c7b\uff0c\u7528\u4e8e\u5230\u6d41\u3002write\u548cprint\u662f\u5b83\u63d0\u4f9b\u7684\u4e24\u4e2a\u91cd\u8981\u65b9\u6cd5\uff0c\u7528\u4e8e\u5411response\u5bf9\u8c61\u5199\u5165\u5b57\u7b26\u6570\u636e\u3002 \u8be6\u89e3 \u867d\u7136write\u548cprint\u65b9\u6cd5\u90fd\u53ef\u5c06\u5b57\u7b26\u6570\u636e\u5199\u5165response\u5bf9\u8c61\uff0c\u4f46\u5b83\u4eec\u7684\u5b9e\u73b0\u548c\u7528\u9014\u6709\u6240\u4e0d\u540c\uff1a \u7acb\u5373\u5b66\u4e60\u201c\u201d\uff1b write\u65b9\u6cd5\uff1a \u5c06\u5b57\u7b26\u6570\u636e\u539f\u6837\u8f93\u51fa\uff0c\u4e0d\u6267\u884c\u4efb\u4f55\u7279\u6b8a\u5904\u7406\u3002 \u4e3b\u8981\u7528\u4e8e\u5199\u5165\u975e\u683c\u5f0f\u5316\u6570\u636e\uff0c\u5982\u4e8c\u8fdb\u5236\u6570\u636e\u6216\u6765\u81ea\u5176\u5b83\u6d41\u7684\u6570\u636e\u3002 print\u65b9\u6cd5\uff1a \u8f93\u51fa\u5b57\u7b26\u6570\u636e\u65f6\uff0c\u4f1a\u5148\u5c06\u5176\u8f6c\u6362\u4e3a\u5b57\u7b26\u4e32\u683c\u5f0f\u3002 \u901a\u5e38\u7528\u4e8e\u5199\u5165\u683c\u5f0f\u5316\u6570\u636e\uff0c\u5982html\u6807\u7b7e\u3001\u6587\u672c\u7b49\u3002 \u5e94\u7528\u573a\u666f \u8003\u8651\u4ee5\u4e0b\u4ee3\u7801\u793a\u4f8b\uff1a PrintWriter out = response.getWriter(); out.write(&#8220;Hello World&#8221;); \/\/ \u8f93\u51fa\u539f\u5b57\u7b26\u6570\u636e out.print(&#8220;&lt;p&gt;Hello World&lt;\/p&gt;&#8221;); \/\/ \u8f93\u51fa\u683c\u5f0f\u5316HTML \u767b\u5f55\u540e\u590d\u5236 \u5728\u4e0a\u9762\u7684\u793a\u4f8b\u4e2d\uff0cwrite\u65b9\u6cd5\u5c06\u201chello world\u201d\u539f\u6837\u8f93\u51fa\uff0c\u800cprint\u65b9\u6cd5\u5c06\u5176\u8f6c\u6362\u4e3ahtml\u683c\u5f0f\u518d\u8f93\u51fa\u3002 \u7ed3\u8bba write\u65b9\u6cd5\u662f\u4f4e\u7ea7\u8f93\u51fa\u65b9\u6cd5\uff0c\u4e3b\u8981\u7528\u4e8e\u5199\u5165\u975e\u683c\u5f0f\u5316\u6570\u636e\u3002print\u65b9\u6cd5\u662f\u9ad8\u7ea7\u8f93\u51fa\u65b9\u6cd5\uff0c\u901a\u5e38\u7528\u4e8e\u5199\u5165\u683c\u5f0f\u5316\u6570\u636e\u3002\u6839\u636e\u5177\u4f53\u9700\u6c42\uff0c\u9009\u62e9\u5408\u9002\u7684\u8f93\u51fa\u65b9\u6cd5\u53ef\u4ee5\u63d0\u5347\u4ee3\u7801\u6e05\u6670\u5ea6\u548c\u7075\u6d3b\u5ea6\u3002 \u4ee5\u4e0a\u5c31\u662fJava \u4e2d PrintWriter \u7684 write \u548c print \u65b9\u6cd5\uff1a\u6709\u54ea\u4e9b\u548c\u5e94\u7528\u573a\u666f\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},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-36073","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/36073","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=36073"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/36073\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=36073"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=36073"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=36073"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}