{"id":668,"date":"2015-05-20T09:39:13","date_gmt":"2015-05-20T01:39:13","guid":{"rendered":"https:\/\/ai.zhousir.top\/?p=668"},"modified":"2026-08-18T12:09:33","modified_gmt":"2026-08-18T04:09:33","slug":"java%e4%b8%ad%e6%96%87%e4%bb%b6%e7%9a%84%e9%9a%8f%e6%9c%ba%e8%af%bb%e5%86%99","status":"publish","type":"post","link":"https:\/\/ai.zhousir.top\/?p=668","title":{"rendered":"Java\u4e2d\u6587\u4ef6\u7684\u968f\u673a\u8bfb\u5199"},"content":{"rendered":"<section id=\"wenyan\" style=\"font-family: system-ui, 'Apple Color Emoji', 'Segoe UI', 'Segoe UI Symbol', 'Noto Sans', Roboto, sans-serif; line-height: 1.75; font-size: 16px; color: #000000; caret-color: #000000;\" data-provider=\"WenYan\">\n<p style=\"margin: 1em 0px;\"><code style=\"font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; color: #4870ac; font-size: 0.9em; font-weight: normal; overflow-wrap: break-word; padding: 2px 4px; border-radius: 3px; margin: 2px; background-color: #f6f8fa; word-break: break-all;\">java.io<\/code> \u5305\u63d0\u4f9b\u4e86 <strong style=\"color: #4870ac;\">RandomAccessFile<\/strong> \u7c7b\uff0c\u7528\u6765\u521b\u5efa\u548c\u8bbf\u95ee\u968f\u673a\u6587\u4ef6\u3002\u4f7f\u7528\u8fd9\u4e2a\u7c7b\uff0c\u53ef\u4ee5\u8df3\u8f6c\u5230\u6587\u4ef6\u7684\u4efb\u610f\u4f4d\u7f6e\u8bfb\u5199\u6570\u636e\uff1a\u63d2\u5165\u65f6\u4e0d\u5fc5\u7834\u574f\u5176\u4f59\u5185\u5bb9\uff0c\u66f4\u65b0\u6216\u5220\u9664\u5148\u524d\u6570\u636e\u65f6\u4e5f\u4e0d\u5fc5\u91cd\u5199\u6574\u4e2a\u6587\u4ef6\u3002<\/p>\n<p><!--more--><\/p>\n<h2 style=\"padding: 1px 12.5px; color: #ffffff; margin: 1.2em 0px 1em; border-radius: 4px; display: inline-block; background-color: #4870ac; font-size: 1.3em;\">\u4e00\u3001\u6784\u9020\u65b9\u6cd5<\/h2>\n<p style=\"margin: 1em 0px;\">RandomAccessFile \u662f Object \u7684\u76f4\u63a5\u5b50\u7c7b\uff0c\u4e3b\u8981\u7528\u4e0b\u9762\u4e24\u4e2a\u6784\u9020\u65b9\u6cd5\u521b\u5efa\u5bf9\u8c61\uff1a<\/p>\n<p style=\"margin: 1em 0px;\"><a href=\"https:\/\/ai.zhousir.top\/wp-content\/uploads\/2015\/05\/file1.jpeg\" rel=\"fancybox\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone  wp-image-669\" src=\"https:\/\/ai.zhousir.top\/wp-content\/uploads\/2015\/05\/file1.jpeg\" alt=\"file1\" width=\"533\" height=\"434\" srcset=\"https:\/\/ai.zhousir.top\/wp-content\/uploads\/2015\/05\/file1.jpeg 746w, https:\/\/ai.zhousir.top\/wp-content\/uploads\/2015\/05\/file1-678x553.jpeg 678w, https:\/\/ai.zhousir.top\/wp-content\/uploads\/2015\/05\/file1-528x430.jpeg 528w\" sizes=\"(max-width: 533px) 100vw, 533px\" \/><\/a><\/p>\n<table style=\"display: table; text-align: left; overflow: auto; border-collapse: collapse; margin: 1.4em auto; max-width: 100%; table-layout: fixed; overflow-wrap: break-word; word-break: break-all;\" width=\"800\">\n<thead>\n<tr>\n<th style=\"border: 1px solid #d9dfe4; padding: 9px 12px; font-size: 0.75em; line-height: 22px; vertical-align: top; text-align: center; font-weight: bold; color: #4870ac; background: #f7f7f7;\">\u6784\u9020\u65b9\u6cd5<\/th>\n<th style=\"border: 1px solid #d9dfe4; padding: 9px 12px; font-size: 0.75em; line-height: 22px; vertical-align: top; text-align: center; font-weight: bold; color: #4870ac; background: #f7f7f7;\">\u8bf4\u660e<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td style=\"border: 1px solid #d9dfe4; padding: 9px 12px; font-size: 0.75em; line-height: 22px; vertical-align: top;\">RandomAccessFile(String name, String mode)<\/td>\n<td style=\"border: 1px solid #d9dfe4; padding: 9px 12px; font-size: 0.75em; line-height: 22px; vertical-align: top;\">\u6309\u6587\u4ef6\u540d\u6253\u5f00\uff1bmode \u5e38\u7528 &#8220;r&#8221; \u53ea\u8bfb\u3001&#8221;rw&#8221; \u8bfb\u5199<\/td>\n<\/tr>\n<tr>\n<td style=\"border: 1px solid #d9dfe4; padding: 9px 12px; font-size: 0.75em; line-height: 22px; vertical-align: top;\">RandomAccessFile(File file, String mode)<\/td>\n<td style=\"border: 1px solid #d9dfe4; padding: 9px 12px; font-size: 0.75em; line-height: 22px; vertical-align: top;\">\u6309 File \u5bf9\u8c61\u6253\u5f00\uff0cmode \u542b\u4e49\u76f8\u540c<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p style=\"margin: 1em 0px;\">\u6587\u4ef6\u6307\u9488\u53ef\u4ee5\u7528 <code style=\"font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; color: #4870ac; font-size: 0.9em; font-weight: normal; overflow-wrap: break-word; padding: 2px 4px; border-radius: 3px; margin: 2px; background-color: #f6f8fa; word-break: break-all;\">seek(long pos)<\/code> \u632a\u5230\u4efb\u610f\u5b57\u8282\u4f4d\u7f6e\uff1b<code style=\"font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; color: #4870ac; font-size: 0.9em; font-weight: normal; overflow-wrap: break-word; padding: 2px 4px; border-radius: 3px; margin: 2px; background-color: #f6f8fa; word-break: break-all;\">length()<\/code> \u7ed9\u51fa\u5f53\u524d\u6587\u4ef6\u957f\u5ea6\uff0c\u5e38\u7528\u6765\u5b9a\u4f4d\u5230\u672b\u5c3e\u8ffd\u52a0\u3002<\/p>\n<h2 style=\"padding: 1px 12.5px; color: #ffffff; margin: 1.2em 0px 1em; border-radius: 4px; display: inline-block; background-color: #4870ac; font-size: 1.3em;\">\u4e8c\u3001\u8ffd\u52a0\u5199\u5165\u65e5\u5fd7<\/h2>\n<p style=\"margin: 1em 0px;\">\u3010\u4f8b 10-12\u3011\u6a21\u4eff\u7cfb\u7edf\u65e5\u5fd7\uff0c\u628a\u952e\u76d8\u8f93\u5165\u5199\u5230\u6587\u4ef6\u5c3e\u90e8\u3002<\/p>\n<pre style=\"overflow: auto hidden; word-break: normal; white-space: pre; tab-size: 2; border-radius: 5px; line-height: 2; margin: 1em 0.5em; padding: 0.5em; box-shadow: rgba(0, 0, 0, 0.55) 0px 1px 5px; font-size: 12px; background: #002b36; max-width: 100%; overflow-wrap: normal;\"><code class=\"hljs\" style=\"word-break: normal; white-space: nowrap; tab-size: 2; font-size: 12px; font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; display: block; overflow-x: auto; margin: 0.5em; padding: 3px 5px; color: #93a1a1; background: #002b36; overflow-wrap: normal;\">import java.io.*;\nclass ep10_12 {\n    public static void main(String args[]) throws IOException {\n        try {\n            BufferedReader in = new BufferedReader(new InputStreamReader(System.in));\n            String s = in.readLine();\n            RandomAccessFile myFile = new RandomAccessFile(\"ep10_12.log\", \"rw\");\n            myFile.seek(myFile.length());  \/\/ \u79fb\u52a8\u5230\u6587\u4ef6\u7ed3\u5c3e\n            myFile.writeBytes(s + \"\\n\");   \/\/ \u5199\u5165\u6570\u636e\n            myFile.close();\n        } catch (IOException e) {}\n    }\n}<\/code><\/pre>\n<p style=\"margin: 1em 0px;\">\u7a0b\u5e8f\u8fd0\u884c\u540e\u4f1a\u5728\u5f53\u524d\u76ee\u5f55\u5efa\u7acb <code style=\"font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; color: #4870ac; font-size: 0.9em; font-weight: normal; overflow-wrap: break-word; padding: 2px 4px; border-radius: 3px; margin: 2px; background-color: #f6f8fa; word-break: break-all;\">ep10_12.log<\/code>\u3002\u6bcf\u6b21\u8fd0\u884c\u8f93\u5165\u7684\u5185\u5bb9\u90fd\u4f1a\u8ffd\u52a0\u5230\u6587\u4ef6\u672b\u5c3e\uff0c\u4e0d\u4f1a\u8986\u76d6\u5df2\u6709\u8bb0\u5f55\u3002<\/p>\n<blockquote style=\"display: block; font-size: 0.9em; border-left: 3px solid #4870ac; padding: 0.5em 1em; margin: 0px; background: #f6f8fa; color: #40464f;\">\n<p style=\"margin: 1em 0px;\"><strong style=\"color: #4870ac;\">\u4e00\u53e5\u8bdd\u603b\u7ed3\uff1aRandomAccessFile \u9760\u6587\u4ef6\u6307\u9488\u968f\u673a\u5b9a\u4f4d\uff1bseek(length()) \u5c31\u80fd\u5728\u5c3e\u90e8\u8ffd\u52a0\uff0c\u4e0d\u5fc5\u91cd\u5199\u6574\u6587\u4ef6\u3002<\/strong><\/p>\n<\/blockquote>\n<\/section>\n","protected":false},"excerpt":{"rendered":"<p>java.io \u5305\u63d0\u4f9b\u4e86 RandomAccessFile \u7c7b\uff0c\u7528\u6765\u521b\u5efa\u548c\u8bbf\u95ee\u968f\u673a\u6587\u4ef6\u3002\u4f7f\u7528\u8fd9\u4e2a\u7c7b\uff0c\u53ef\u4ee5\u8df3\u8f6c\u5230 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[22],"tags":[41],"_links":{"self":[{"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=\/wp\/v2\/posts\/668"}],"collection":[{"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=668"}],"version-history":[{"count":2,"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=\/wp\/v2\/posts\/668\/revisions"}],"predecessor-version":[{"id":671,"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=\/wp\/v2\/posts\/668\/revisions\/671"}],"wp:attachment":[{"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=668"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=668"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=668"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}