{"id":64152,"date":"2025-05-03T08:56:57","date_gmt":"2025-05-03T00:56:57","guid":{"rendered":"https:\/\/fwq.ai\/blog\/64152\/"},"modified":"2025-05-03T08:56:57","modified_gmt":"2025-05-03T00:56:57","slug":"java%e6%80%8e%e4%b9%88%e4%bb%8e%e9%94%ae%e7%9b%98%e8%be%93%e5%85%a5byte%e6%95%b0%e7%bb%84-2","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/64152\/","title":{"rendered":"java\u600e\u4e48\u4ece\u952e\u76d8\u8f93\u5165byte\u6570\u7ec4"},"content":{"rendered":"<blockquote><p>\n  java \u4e2d\u53ef\u901a\u8fc7\u5982\u4e0b\u65b9\u6cd5\u4ece\u952e\u76d8\u8f93\u5165\u5b57\u8282\u6570\u7ec4\uff1a\u4f7f\u7528 scanner \u7c7b\uff1a\u521b\u5efa\u4e00\u4e2a scanner \u5bf9\u8c61\uff0c\u4f7f\u7528 nextline() \u8bfb\u53d6\u952e\u76d8\u8f93\u5165\u7684\u4e00\u884c\uff0c\u518d\u5c06\u5b57\u7b26\u4e32\u8f6c\u6362\u4e3a\u5b57\u8282\u6570\u7ec4\u3002\u4f7f\u7528 datainputstream\uff1a\u8bfb\u53d6\u4e8c\u8fdb\u5236\u6570\u636e\uff0c\u5305\u62ec\u5b57\u8282\u6570\u7ec4\u3002\u4f7f\u7528 bufferedreader\uff1a\u8bfb\u53d6\u5b57\u7b26\u6d41\uff0c\u4f7f\u7528 readline() \u8bfb\u53d6\u4e00\u884c\u5e76\u8f6c\u6362\u4e3a\u5b57\u8282\u6570\u7ec4\u3002\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202411\/02\/2024110215391717239.jpg\" class=\"aligncenter\" title=\"java\u600e\u4e48\u4ece\u952e\u76d8\u8f93\u5165byte\u6570\u7ec4\u63d2\u56fe\" alt=\"java\u600e\u4e48\u4ece\u952e\u76d8\u8f93\u5165byte\u6570\u7ec4\u63d2\u56fe\" \/><\/p>\n<p><strong>\u5982\u4f55\u4f7f\u7528 Java \u4ece\u952e\u76d8\u8f93\u5165\u5b57\u8282\u6570\u7ec4\uff1f<\/strong><\/p>\n<p><strong>\u5f15\u8a00<\/strong><\/p>\n<p>Java \u4e2d\u6709\u51e0\u79cd\u65b9\u6cd5\u53ef\u4ee5\u4ece\u952e\u76d8\u8f93\u5165\u5b57\u8282\u6570\u7ec4\u3002\u5176\u4e2d\u6700\u5e38\u89c1\u7684\u65b9\u6cd5\u662f\u4f7f\u7528 Scanner \u7c7b\u3002<\/p>\n<p><strong>\u4f7f\u7528 Scanner \u7c7b<\/strong><\/p>\n<p><span>\u7acb\u5373\u5b66\u4e60<\/span>\u201c\u201d\uff1b<\/p>\n<p>Scanner \u7c7b\u7684 nextLine() \u65b9\u6cd5\u53ef\u4ee5\u8bfb\u53d6\u952e\u76d8\u8f93\u5165\u7684\u4e00\u884c\uff0c\u5c06\u5176\u89e3\u6790\u4e3a\u5b57\u7b26\u4e32\uff0c\u7136\u540e\u5c06\u5176\u8f6c\u6362\u4e3a\u5b57\u8282\u6570\u7ec4\u3002<\/p>\n<pre>import java.util.Scanner;\n\npublic class InputByteArray {\n    public static void main(String[] args) {\n        Scanner scanner = new Scanner(System.in);\n        System.out.print(\"\u8f93\u5165\u5b57\u8282\u6570\u7ec4\uff1a\");\n        String input = scanner.nextLine();\n        byte[] byteArray = input.getBytes();\n        System.out.println(\"\u8f93\u5165\u7684\u5b57\u8282\u6570\u7ec4\uff1a\" + byteArray);\n    }\n}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u6b65\u9aa4\uff1a<\/strong><\/p>\n<ol>\n<li>\u521b\u5efa\u4e00\u4e2a Scanner \u5bf9\u8c61\uff0c\u8be5\u5bf9\u8c61\u8fde\u63a5\u5230\u6807\u51c6\u8f93\u5165\uff08\u952e\u76d8\uff09\u3002<\/li>\n<li>\u4f7f\u7528 nextLine() \u65b9\u6cd5\u4ece\u952e\u76d8\u8bfb\u53d6\u4e00\u884c\u3002<\/li>\n<li>\u5c06\u5b57\u7b26\u4e32\u8f6c\u6362\u4e3a\u5b57\u8282\u6570\u7ec4\uff0c\u53ef\u4ee5\u4f7f\u7528 getBytes() \u65b9\u6cd5\u3002<\/li>\n<li>\u6253\u5370\u5b57\u8282\u6570\u7ec4\u3002<\/li>\n<\/ol>\n<p><strong>\u5176\u4ed6\u65b9\u6cd5<\/strong><\/p>\n<p>\u9664\u4e86 Scanner \u7c7b\u4e4b\u5916\uff0c\u8fd8\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u65b9\u6cd5\u4ece\u952e\u76d8\u8f93\u5165\u5b57\u8282\u6570\u7ec4\uff1a<\/p>\n<ul>\n<li> <strong>DataInputStream\uff1a<\/strong>\u8bfb\u53d6\u4e8c\u8fdb\u5236\u6570\u636e\uff0c\u5305\u62ec\u5b57\u8282\u6570\u7ec4\u3002<\/li>\n<li> <strong>BufferedReader\uff1a<\/strong>\u8bfb\u53d6\u5b57\u7b26\u6d41\uff0c\u53ef\u4ee5\u4f7f\u7528 readLine() \u65b9\u6cd5\u8bfb\u53d6\u4e00\u884c\u5e76\u5c06\u5176\u8f6c\u6362\u4e3a\u5b57\u8282\u6570\u7ec4\u3002<\/li>\n<\/ul>\n<p><strong>\u63d0\u793a<\/strong><\/p>\n<ul>\n<li>\u786e\u4fdd\u8f93\u5165\u7684\u5b57\u7b26\u4e32\u662f\u6709\u6548\u7684\u5b57\u8282\u6570\u7ec4\u8868\u793a\u5f62\u5f0f\u3002<\/li>\n<li>\u5982\u679c\u9700\u8981\u8f93\u5165\u591a\u4e2a\u5b57\u8282\u6570\u7ec4\u5143\u7d20\uff0c\u53ef\u4ee5\u4f7f\u7528\u5faa\u73af\u6216\u6b63\u5219\u8868\u8fbe\u5f0f\u6765\u89e3\u6790\u8f93\u5165\u3002<\/li>\n<\/ul>\n<p>\u4ee5\u4e0a\u5c31\u662fjava\u600e\u4e48\u4ece\u952e\u76d8\u8f93\u5165byte\u6570\u7ec4\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8IDCBABY\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>java \u4e2d\u53ef\u901a\u8fc7\u5982\u4e0b\u65b9\u6cd5\u4ece\u952e\u76d8\u8f93\u5165\u5b57\u8282\u6570\u7ec4\uff1a\u4f7f\u7528 scanner \u7c7b\uff1a\u521b\u5efa\u4e00\u4e2a scanner \u5bf9\u8c61\uff0c\u4f7f\u7528 nextline() \u8bfb\u53d6\u952e\u76d8\u8f93\u5165\u7684\u4e00\u884c\uff0c\u518d\u5c06\u5b57\u7b26\u4e32\u8f6c\u6362\u4e3a\u5b57\u8282\u6570\u7ec4\u3002\u4f7f\u7528 datainputstream\uff1a\u8bfb\u53d6\u4e8c\u8fdb\u5236\u6570\u636e\uff0c\u5305\u62ec\u5b57\u8282\u6570\u7ec4\u3002\u4f7f\u7528 bufferedreader\uff1a\u8bfb\u53d6\u5b57\u7b26\u6d41\uff0c\u4f7f\u7528 readline() \u8bfb\u53d6\u4e00\u884c\u5e76\u8f6c\u6362\u4e3a\u5b57\u8282\u6570\u7ec4\u3002 \u5982\u4f55\u4f7f\u7528 Java \u4ece\u952e\u76d8\u8f93\u5165\u5b57\u8282\u6570\u7ec4\uff1f \u5f15\u8a00 Java \u4e2d\u6709\u51e0\u79cd\u65b9\u6cd5\u53ef\u4ee5\u4ece\u952e\u76d8\u8f93\u5165\u5b57\u8282\u6570\u7ec4\u3002\u5176\u4e2d\u6700\u5e38\u89c1\u7684\u65b9\u6cd5\u662f\u4f7f\u7528 Scanner \u7c7b\u3002 \u4f7f\u7528 Scanner \u7c7b \u7acb\u5373\u5b66\u4e60\u201c\u201d\uff1b Scanner \u7c7b\u7684 nextLine() \u65b9\u6cd5\u53ef\u4ee5\u8bfb\u53d6\u952e\u76d8\u8f93\u5165\u7684\u4e00\u884c\uff0c\u5c06\u5176\u89e3\u6790\u4e3a\u5b57\u7b26\u4e32\uff0c\u7136\u540e\u5c06\u5176\u8f6c\u6362\u4e3a\u5b57\u8282\u6570\u7ec4\u3002 import java.util.Scanner; public class InputByteArray { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); System.out.print(&#8220;\u8f93\u5165\u5b57\u8282\u6570\u7ec4\uff1a&#8221;); String input = scanner.nextLine(); byte[] byteArray = input.getBytes(); System.out.println(&#8220;\u8f93\u5165\u7684\u5b57\u8282\u6570\u7ec4\uff1a&#8221; [&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-64152","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/64152","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=64152"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/64152\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=64152"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=64152"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=64152"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}