{"id":37378,"date":"2024-11-26T09:22:45","date_gmt":"2024-11-26T01:22:45","guid":{"rendered":"https:\/\/fwq.ai\/blog\/37378\/"},"modified":"2024-11-26T09:22:45","modified_gmt":"2024-11-26T01:22:45","slug":"java%e6%80%8e%e4%b9%88%e5%ba%8f%e5%88%97%e5%8c%96%e6%95%b0%e7%bb%84","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/37378\/","title":{"rendered":"java\u600e\u4e48\u5e8f\u5217\u5316\u6570\u7ec4"},"content":{"rendered":"<blockquote><p>\n  \u6570\u7ec4\u5e8f\u5217\u5316\u548c\u53cd\u5e8f\u5217\u5316\u65b9\u6cd5\uff1a\u5e8f\u5217\u5316\u6570\u7ec4\uff1a\u4f7f\u7528 objectoutputstream \u7c7b\u5c06\u6570\u7ec4\u5199\u5165\u6587\u4ef6\u3002\u53cd\u5e8f\u5217\u5316\u6570\u7ec4\uff1a\u4f7f\u7528 objectinputstream \u7c7b\u4ece\u6587\u4ef6\u4e2d\u8bfb\u5165\u6570\u7ec4\u3002\u6ce8\u610f\uff1a\u6570\u7ec4\u548c\u6570\u7ec4\u5143\u7d20\u5fc5\u987b\u5b9e\u73b0 serializable \u63a5\u53e3\u3002\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202411\/13\/2024111304481655817.jpg\" class=\"aligncenter\" title=\"java\u600e\u4e48\u5e8f\u5217\u5316\u6570\u7ec4\u63d2\u56fe\" alt=\"java\u600e\u4e48\u5e8f\u5217\u5316\u6570\u7ec4\u63d2\u56fe\" \/><\/p>\n<p><strong>Java \u5e8f\u5217\u5316\u6570\u7ec4<\/strong><\/p>\n<p>Java \u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528 java.io.ObjectOutputStream \u548c java.io.ObjectInputStream \u7c7b\u5bf9\u6570\u7ec4\u8fdb\u884c\u5e8f\u5217\u5316\u548c\u53cd\u5e8f\u5217\u5316\u3002<\/p>\n<p><strong>\u5e8f\u5217\u5316\u6570\u7ec4\u7684\u65b9\u6cd5<\/strong><\/p>\n<pre>\/\/ \u521b\u5efa\u4e00\u4e2a ObjectOutputStream \u5bf9\u8c61\nObjectOutputStream out = new ObjectOutputStream(new FileOutputStream(\"array.dat\"));\n\n\/\/ \u5199\u5165\u6570\u7ec4\nout.writeObject(array);\n\n\/\/ \u5173\u95ed\u6d41\nout.close();<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u53cd\u5e8f\u5217\u5316\u6570\u7ec4\u7684\u65b9\u6cd5<\/strong><\/p>\n<p><span>\u7acb\u5373\u5b66\u4e60<\/span>\u201c\u201d\uff1b<\/p>\n<pre>\/\/ \u521b\u5efa\u4e00\u4e2a ObjectInputStream \u5bf9\u8c61\nObjectInputStream in = new ObjectInputStream(new FileInputStream(\"array.dat\"));\n\n\/\/ \u8bfb\u5165\u6570\u7ec4\nint[] array = (int[]) in.readObject();\n\n\/\/ \u5173\u95ed\u6d41\nin.close();<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u6ce8\u610f\uff1a<\/strong><\/p>\n<ul>\n<li>\u88ab\u5e8f\u5217\u5316\u7684\u6570\u7ec4\u5fc5\u987b\u5b9e\u73b0 Serializable \u63a5\u53e3\u3002<\/li>\n<li>\u6570\u7ec4\u4e2d\u7684\u5143\u7d20\u4e5f\u5fc5\u987b\u5b9e\u73b0 Serializable \u63a5\u53e3\u3002<\/li>\n<\/ul>\n<p>\u4ee5\u4e0a\u5c31\u662fjava\u600e\u4e48\u5e8f\u5217\u5316\u6570\u7ec4\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>\u6570\u7ec4\u5e8f\u5217\u5316\u548c\u53cd\u5e8f\u5217\u5316\u65b9\u6cd5\uff1a\u5e8f\u5217\u5316\u6570\u7ec4\uff1a\u4f7f\u7528 objectoutputstream \u7c7b\u5c06\u6570\u7ec4\u5199\u5165\u6587\u4ef6\u3002\u53cd\u5e8f\u5217\u5316\u6570\u7ec4\uff1a\u4f7f\u7528 objectinputstream \u7c7b\u4ece\u6587\u4ef6\u4e2d\u8bfb\u5165\u6570\u7ec4\u3002\u6ce8\u610f\uff1a\u6570\u7ec4\u548c\u6570\u7ec4\u5143\u7d20\u5fc5\u987b\u5b9e\u73b0 serializable \u63a5\u53e3\u3002 Java \u5e8f\u5217\u5316\u6570\u7ec4 Java \u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528 java.io.ObjectOutputStream \u548c java.io.ObjectInputStream \u7c7b\u5bf9\u6570\u7ec4\u8fdb\u884c\u5e8f\u5217\u5316\u548c\u53cd\u5e8f\u5217\u5316\u3002 \u5e8f\u5217\u5316\u6570\u7ec4\u7684\u65b9\u6cd5 \/\/ \u521b\u5efa\u4e00\u4e2a ObjectOutputStream \u5bf9\u8c61 ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream(&#8220;array.dat&#8221;)); \/\/ \u5199\u5165\u6570\u7ec4 out.writeObject(array); \/\/ \u5173\u95ed\u6d41 out.close(); \u767b\u5f55\u540e\u590d\u5236 \u53cd\u5e8f\u5217\u5316\u6570\u7ec4\u7684\u65b9\u6cd5 \u7acb\u5373\u5b66\u4e60\u201c\u201d\uff1b \/\/ \u521b\u5efa\u4e00\u4e2a ObjectInputStream \u5bf9\u8c61 ObjectInputStream in = new ObjectInputStream(new FileInputStream(&#8220;array.dat&#8221;)); \/\/ \u8bfb\u5165\u6570\u7ec4 int[] array = (int[]) in.readObject(); \/\/ \u5173\u95ed\u6d41 in.close(); [&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-37378","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/37378","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=37378"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/37378\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=37378"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=37378"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=37378"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}