{"id":263,"date":"2015-04-17T19:59:17","date_gmt":"2015-04-17T11:59:17","guid":{"rendered":"https:\/\/ai.zhousir.top\/?p=263"},"modified":"2026-08-18T12:09:30","modified_gmt":"2026-08-18T04:09:30","slug":"java-io-%e6%93%8d%e4%bd%9c%e5%ae%9e%e4%be%8b%e6%b1%87%e6%80%bb","status":"publish","type":"post","link":"https:\/\/ai.zhousir.top\/?p=263","title":{"rendered":"Java IO \u64cd\u4f5c\u5b9e\u4f8b\u6c47\u603b"},"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;\">\u8fd9\u7bc7\u662f <strong style=\"color: #4870ac;\">Java IO<\/strong> \u5b66\u4e60\u7b14\u8bb0\u52a0\u4ee3\u7801\uff1a\u4ece <strong style=\"color: #4870ac;\">File<\/strong> \u5bf9\u8c61\u7684\u751f\u6210\u3001\u521b\u5efa\u3001\u6539\u540d\u548c\u5c5e\u6027\u6d4b\u8bd5\uff0c\u8bb2\u5230\u62f7\u8d1d\u3001\u968f\u673a\u8bbf\u95ee\u3001\u5b57\u7b26\u6d41\u3001\u952e\u76d8\u8f93\u5165\u3001\u8fc7\u6ee4\u6d41\u3001\u987a\u5e8f\u6d41\u548c\u5bf9\u8c61\u4e32\u884c\u5316\u3002<\/p>\n<p style=\"margin: 1em 0px;\">\u6bcf\u4e2a\u4e3b\u9898\u90fd\u914d\u6709\u5b8c\u6574\u53ef\u8fd0\u884c\u793a\u4f8b\uff08\u5305\u540d study.iostudy\uff09\uff0c\u8986\u76d6 mkdir\/createNewFile\u3001FilenameFilter\u3001FileInputStream\/FileOutputStream\u3001RandomAccessFile\u3001Reader\/Writer \u7f13\u51b2\u6d41\u3001DataInputStream\u3001PushbackInputStream\u3001SequenceInputStream \u548c Serializable\u3002<\/p>\n<p><!--more--><\/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;\">\u4e3b\u9898<\/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;\">\u6838\u5fc3\u7c7b<\/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;\">\u8981\u70b9<\/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;\">\u6587\u4ef6\u5bf9\u8c61<\/td>\n<td style=\"border: 1px solid #d9dfe4; padding: 9px 12px; font-size: 0.75em; line-height: 22px; vertical-align: top;\">File<\/td>\n<td style=\"border: 1px solid #d9dfe4; padding: 9px 12px; font-size: 0.75em; line-height: 22px; vertical-align: top;\">mkdir \/ createNewFile \/ \u8def\u5f84\u4e0e\u5c5e\u6027<\/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;\">\u76ee\u5f55\u5217\u4e3e<\/td>\n<td style=\"border: 1px solid #d9dfe4; padding: 9px 12px; font-size: 0.75em; line-height: 22px; vertical-align: top;\">FilenameFilter<\/td>\n<td style=\"border: 1px solid #d9dfe4; padding: 9px 12px; font-size: 0.75em; line-height: 22px; vertical-align: top;\">\u6309\u6269\u5c55\u540d\u6216\u524d\u7f00\u8fc7\u6ee4<\/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;\">\u5b57\u8282\u62f7\u8d1d<\/td>\n<td style=\"border: 1px solid #d9dfe4; padding: 9px 12px; font-size: 0.75em; line-height: 22px; vertical-align: top;\">FileInputStream \/ FileOutputStream<\/td>\n<td style=\"border: 1px solid #d9dfe4; padding: 9px 12px; font-size: 0.75em; line-height: 22px; vertical-align: top;\">\u7f13\u51b2\u6570\u7ec4\u8bfb\u5199\u4efb\u610f\u6587\u4ef6<\/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;\">\u968f\u673a\u8bbf\u95ee<\/td>\n<td style=\"border: 1px solid #d9dfe4; padding: 9px 12px; font-size: 0.75em; line-height: 22px; vertical-align: top;\">RandomAccessFile<\/td>\n<td style=\"border: 1px solid #d9dfe4; padding: 9px 12px; font-size: 0.75em; line-height: 22px; vertical-align: top;\">seek \/ getFilePointer \/ readLine<\/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;\">\u5b57\u7b26\u6d41<\/td>\n<td style=\"border: 1px solid #d9dfe4; padding: 9px 12px; font-size: 0.75em; line-height: 22px; vertical-align: top;\">InputStreamReader \/ BufferedReader<\/td>\n<td style=\"border: 1px solid #d9dfe4; padding: 9px 12px; font-size: 0.75em; line-height: 22px; vertical-align: top;\">\u6309\u5e73\u53f0\u7f16\u7801\u6865\u63a5\u5b57\u8282\u4e0e\u5b57\u7b26<\/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;\">\u8fc7\u6ee4\/\u987a\u5e8f\/\u4e32\u884c\u5316<\/td>\n<td style=\"border: 1px solid #d9dfe4; padding: 9px 12px; font-size: 0.75em; line-height: 22px; vertical-align: top;\">Filter* \/ SequenceInputStream \/ Serializable<\/td>\n<td style=\"border: 1px solid #d9dfe4; padding: 9px 12px; font-size: 0.75em; line-height: 22px; vertical-align: top;\">\u7f13\u51b2\u3001\u56de\u9000\u3001\u591a\u6d41\u62fc\u63a5\u3001\u5bf9\u8c61\u72b6\u6001\u4fdd\u5b58<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\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;\">Java IO\u5b66\u4e60\u7b14\u8bb0+\u4ee3\u7801<\/h2>\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;\">\u6587\u4ef6\u5bf9\u8c61\u7684\u751f\u6210\u548c\u6587\u4ef6\u7684\u521b\u5efa<\/h2>\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;\">\/*\n * ProcessFileName.java\n *\n *\n * \u6587\u4ef6\u5bf9\u8c61\u7684\u751f\u6210\u548c\u6587\u4ef6\u7684\u521b\u5efa\n *\/\npackage study.iostudy;\nimport java.io.*;\npublic class GenerateFile\n{\n    public static void main(String[] args)\n    {\n        File dirObject = new File(\"d:\\\\mydir\");\n        File fileObject1 = new File(\"oneFirst.txt\");\n        File fileObject2 = new File(\"d:\\\\mydir\", \"firstFile.txt\");\n        System.out.println(fileObject2);\n        try\n        {\n            dirObject.mkdir();\n        }catch(SecurityException e)\n        {\n            e.printStackTrace();\n        }\n        try\n        {\n            fileObject2.createNewFile();\n            fileObject1.createNewFile();\n        }catch(IOException e)\n        {\n            e.printStackTrace();\n        }\n    }\n}<\/code><\/pre>\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;\">\u6587\u4ef6\u540d\u7684\u5904\u7406<\/h2>\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;\">\/*\n * ProcessFileName.java\n *\n *\n * \u6587\u4ef6\u540d\u7684\u5904\u7406\n *\/\npackage study.iostudy;\nimport java.io.*;\n\/*\n * \u6587\u4ef6\u540d\u7684\u5904\u7406\n * String getName(); \u83b7\u5f97\u6587\u4ef6\u7684\u540d\u79f0\uff0c\u4e0d\u5305\u542b\u6587\u4ef6\u6240\u5728\u7684\u8def\u5f84\u3002\n * String getPath(); \u83b7\u5f97\u6587\u4ef6\u7684\u8def\u5f84\u3002\n * String getAbsolutePath(); \u83b7\u5f97\u6587\u4ef6\u7684\u7edd\u5bf9\u8def\u5f84\u3002\n * String getParent(); \u83b7\u5f97\u6587\u4ef6\u7684\u4e0a\u4e00\u7ea7\u76ee\u5f55\u7684\u540d\u79f0\u3002\n * String renameTo(File newName); \u6309\u53c2\u6570\u4e2d\u7ed9\u5b9a\u7684\u5b8c\u6574\u8def\u5f84\u66f4\u6539\u5f53\u524d\u7684\u6587\u4ef6\u540d\u3002\n * int compareTo(File pathName); \u6309\u7167\u5b57\u5178\u987a\u5e8f\u6bd4\u8f83\u4e24\u4e2a\u6587\u4ef6\u5bf9\u8c61\u7684\u8def\u5f84\u3002\n * boolean isAbsolute(); \u6d4b\u8bd5\u6587\u4ef6\u5bf9\u8c61\u7684\u8def\u5f84\u662f\u4e0d\u662f\u7edd\u5bf9\u8def\u5f84\u3002\n *\/\npublic class ProcesserFileName\n{   \n    public static void main(String[] args)\n    {\n        File fileObject1 = new File(\"d:\\\\mydir\\\\firstFile.txt\");\n        File fileObject2 = new File(\"d:\\\\firstFile.txt\");\n        boolean pathAbsolute = fileObject1.isAbsolute();\n        System.out.println(\"* * * * * * * * * * * * * * * * * * * * * * * * \");\n        System.out.println(\"There are some information of fileObject1's file name:\");\n        System.out.println(\"fileObject1: \" + fileObject1);  \n        System.out.println(\"fileObject2: \" + fileObject2);\n        System.out.println(\"file name: \" + fileObject1.getName());\n        System.out.println(\"file path: \" + fileObject1.getPath());\n        System.out.println(\"file absolute path: \" + fileObject1.getAbsolutePath());\n        System.out.println(\"file's parent directory: \" + fileObject1.getParent());\n        System.out.println(\"file's absoulte path: \" + pathAbsolute);\n        int sameName = fileObject1.compareTo(fileObject2);\n        System.out.println(\"fileObject1 compare to fileObject2: \" + sameName);\n        fileObject1.renameTo(fileObject2);\n        System.out.println(\"file's new name: \" + fileObject1.getName());\n    }\n}<\/code><\/pre>\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;\">\u6d4b\u8bd5\u548c\u8bbe\u7f6e\u6587\u4ef6\u5c5e\u6027<\/h2>\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;\">\/*\n * SetterFileAttribute.java\n *\n * Created on 2006\u5e748\u670822\u65e5, \u4e0b\u53483:51\n *\n * \u6d4b\u8bd5\u548c\u8bbe\u7f6e\u6587\u4ef6\u5c5e\u6027\n *\/\npackage study.iostudy;\nimport java.io.*;\npublic class SetterFileAttribute\n{\n    \/*\n     * File\u7c7b\u4e2d\u63d0\u4f9b\u7684\u6709\u5173\u6587\u4ef6\u5c5e\u6027\u6d4b\u8bd5\u65b9\u9762\u7684\u65b9\u6cd5\u6709\u4ee5\u4e0b\u51e0\u79cd\uff1a\n     * boolean exists(); \u6d4b\u8bd5\u5f53\u524d\u6587\u4ef6\u5bf9\u8c61\u6307\u793a\u7684\u6587\u4ef6\u662f\u5426\u5b58\u5728\u3002\n     * boolean isFile(); \u6d4b\u8bd5\u5f53\u524d\u6587\u4ef6\u5bf9\u8c61\u662f\u4e0d\u662f\u6587\u4ef6\u3002\n     * boolean isDirectory(); \u6d4b\u8bd5\u5f53\u524d\u6587\u4ef6\u5bf9\u8c61\u662f\u4e0d\u662f\u76ee\u5f55\u3002\n     * boolean canRead(); \u6d4b\u8bd5\u5f53\u524d\u6587\u4ef6\u5bf9\u8c61\u662f\u5426\u53ef\u8bfb\u3002\n     * boolean canWrite(); \u6d4b\u8bd5\u5f53\u524d\u6587\u4ef6\u5bf9\u8c61\u662f\u5426\u53ef\u5199\u3002\n     * boolean setReadOnly(); \u5c06\u5f53\u524d\u6587\u4ef6\u5bf9\u8c61\u8bbe\u7f6e\u4e3a\u53ea\u8bfb\u3002\n     * long length(); \u83b7\u5f97\u5f53\u524d\u6587\u4ef6\u5bf9\u8c61\u7684\u957f\u5ea6\u3002\n     *\/\n    public static void main(String[] args)\n    {\n        File dirObject = new File(\"d:\\\\mydir\");\n        File fileObject = new File(\"d:\\\\mydir\\\\firstFile.txt\");\n        try\n        {\n            dirObject.mkdir();\n            fileObject.createNewFile();\n        }catch(IOException e)\n        {\n            e.printStackTrace();\n        }\n        System.out.println(\"* * * * * * * * * * * * * * * * * * * * * * * * \");\n        System.out.println(\"there are some information about property of file object:\");\n        System.out.println(\"file object : \" + fileObject);\n        System.out.println(\"file exist? \" + fileObject.exists());\n        System.out.println(\"Is a file? \" + fileObject.isFile());\n        System.out.println(\"Is a directory?\" + fileObject.isDirectory());\n        System.out.println(\"Can read this file? \" + fileObject.canRead());\n        System.out.println(\"Can write this fie? \" + fileObject.canWrite());\n        long fileLen = fileObject.length();\n        System.out.println(\"file length: \" +fileLen);\n        boolean fileRead = fileObject.setReadOnly();\n        System.out.println(fileRead);\n        System.out.println(\"Can read this file? \" + fileObject.canRead());\n        System.out.println(\"Can write this fie? \" + fileObject.canWrite());\n        System.out.println(\"* * * * * * * * * * * * * * * * * * * * * * * * \");\n    }\n}<\/code><\/pre>\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;\">\u6587\u4ef6\u64cd\u4f5c\u65b9\u6cd5<\/h2>\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;\">\/*\n * FileOperation.java\n *\n *\n * \u6587\u4ef6\u64cd\u4f5c\u65b9\u6cd5\n *\/\n\npackage study.iostudy;\nimport java.io.*;\n\/*\n * \u6709\u5173\u6587\u4ef6\u64cd\u4f5c\u65b9\u9762\u7684\u65b9\u6cd5\u6709\u5982\u4e0b\u51e0\u79cd:\n * boolean createNewFile(); \u6839\u636e\u5f53\u524d\u7684\u6587\u4ef6\u5bf9\u8c61\u521b\u5efa\u4e00\u4e2a\u65b0\u7684\u6587\u4ef6\u3002\n * boolean mkdir(); \u6839\u636e\u5f53\u524d\u7684\u6587\u4ef6\u5bf9\u8c61\u751f\u6210\u4e00\u76ee\u5f55\uff0c\u4e5f\u5c31\u662f\u6307\u5b9a\u8def\u5f84\u4e0b\u7684\u6587\u4ef6\u5939\u3002\n * boolean mkdirs(); \u4e5f\u662f\u6839\u636e\u5f53\u524d\u7684\u6587\u4ef6\u5bf9\u8c61\u751f\u6210\u4e00\u4e2a\u76ee\u5f55\uff0c\n *                   \u4e0d\u540c\u7684\u5730\u65b9\u5728\u4e8e\u8be5\u65b9\u6cd5\u5373\u4f7f\u521b\u5efa\u76ee\u5f55\u5931\u8d25\uff0c\n *                   \u4e5f\u4f1a\u6210\u529f\u53c2\u6570\u4e2d\u6307\u5b9a\u7684\u6240\u6709\u7236\u76ee\u5f55\u3002\n * boolean delete(); \u5220\u9664\u5f53\u524d\u7684\u6587\u4ef6\u3002\n * void deleteOnExit(); \u5f53\u524dJava\u865a\u62df\u673a\u7ec8\u6b62\u65f6\u5220\u9664\u5f53\u524d\u7684\u6587\u4ef6\u3002\n * String list(); \u5217\u51fa\u5f53\u524d\u76ee\u5f55\u4e0b\u7684\u6587\u4ef6\u3002\n *\/\npublic class FileOperation\n{\n    public static void main(String[] args)\n    {\n        File fileObject = new File(\"d:\\\\mydir\", \"firstFile.txt\");\n        File dirObject1 = new File(\"d:\\\\mydir\\\\01\");\n        File dirObject2 = new File(\"d:\\\\mydir\\\\02\");\n        File dirObject3 = new File(\"d:\\\\mydir\");\n        System.out.println(\"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\");\n        System.out.println(\"file object: \" + fileObject);\n        System.out.println(\"dir object 1: \" + dirObject1);\n        System.out.println(\"dir object 2\" + dirObject2);\n        try\n        {\n            dirObject1.mkdir();\n            dirObject2.mkdirs();\n        }catch(SecurityException e)\n        {\n            e.printStackTrace();\n        }\n        try\n        {\n            fileObject.createNewFile();\n        }catch(IOException e)\n        {\n            e.printStackTrace();\n        }\n        String[] files = dirObject2.list();\n        for (int i = 0; i &lt; files.length; i++)\n        {\n            System.out.println(\"list files in myhdir: \" + files[i]);\n        }\n        System.out.println(\"dir object 1 exist? \" + dirObject1.exists());\n        System.out.println(\"dir object 2 exist? \" + dirObject2.exists());\n        boolean dir1Del = dirObject1.delete();\n        dirObject2.deleteOnExit();\n        System.out.println(\"dir object 1 exist? \" + dirObject1.exists());\n        System.out.println(\"dir object 2 exist? \" + dirObject2.exists());\n    }\n}<\/code><\/pre>\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;\">\u627e\u51fa\u4e00\u4e2a\u76ee\u5f55\u4e0b\u6240\u6709\u7684\u6587\u4ef6<\/h2>\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;\">\/*\n * SearchFile.java\n *\n *\n * \u627e\u51fa\u4e00\u4e2a\u76ee\u5f55\u4e0b\u6240\u6709\u7684\u6587\u4ef6\n *\/\npackage study.iostudy;\nimport java.io.*;\npublic class SearchFile\n{\n    public static void main(String[] args)\n    {\n        File dirObject = new File(\"D:\\\\aa\");\n        Filter1 filterObj1 = new Filter1(\"HTML\");\n        Filter2 filterObj2 = new Filter2(\"Applet\");\n        System.out.println(\"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\");\n        System.out.println(\"list HTML files in directory: \" + dirObject);\n        String[] filesObj1 = dirObject.list(filterObj1);\n        for (int i = 0; i &lt; filesObj1.length; i++)\n        {\n            File fileObject = new File(dirObject, filesObj1[i]);\n            System.out.println(((fileObject.isFile())\n                ? \"HTML file: \" : \"sub directory: \") + fileObject);\n        }\n        System.out.println(\"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\");\n        String[] filesObj2 = dirObject.list(filterObj2);\n        for (int i = 0; i &lt; filesObj2.length; i++)\n        {\n            File fileObject = new File(dirObject, filesObj2[i]);\n            System.out.println(((fileObject.isFile())\n                ? \"htm file: \" : \"sub directory: \") + fileObject);\n        }\n    }\n}\n\nclass Filter1 implements FilenameFilter\n{\n   String fileExtent;\n    Filter1(String extentObj)\n    {\n        fileExtent = extentObj;\n    }\n\n    public boolean accept(File dir, String name)\n    {\n        return name.endsWith(\".\" + fileExtent);\n    }\n}\n\nclass Filter2 implements FilenameFilter\n{\n    String fileName;\n    Filter2(String fileName)\n    {\n        this.fileName = fileName;\n    }\n\n    public boolean accept(File dir, String name)\n    {\n        return name.startsWith(fileName + \".\");\n    }\n}<\/code><\/pre>\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;\">\u6587\u4ef6\u5185\u5bb9\u7684\u62f7\u8d1d(\u4efb\u610f\u6587\u4ef6)<\/h2>\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;\">\/*\n * CopyFileContent.java\n *\n *\n * \u6587\u4ef6\u5185\u5bb9\u7684\u62f7\u8d1d(\u4efb\u610f\u6587\u4ef6)\n *\/\n\npackage study.iostudy;\nimport java.io.*;\npublic class CopyFileContent\n{\n    static void copyContent(FileInputStream inObj, FileOutputStream outObj)\n   {\n        int copyLen;\n        byte[] copyBuf = new byte[1024];\n        try\n        {\n            while ((copyLen = inObj.read(copyBuf, 0, 1024)) != -1)\n            {\n                String copyStr = new String(copyBuf);\n                System.out.println(copyStr);\n                outObj.write(copyBuf, 0, copyLen);\n            }\n        }catch(IOException e)\n        {\n            System.out.println(\"error: \" + e);\n        }\n    }\n\n    public static void main(String[] args)\n    {\n        String secondFileName = \"d:\\\\mydir\\\\secondFile.wmv\";\n        String thirdFileName = \"d:\\\\mydir\\\\thirdFile.wmv\";\n        File fileObject = new File(thirdFileName);\n        FileInputStream inStream;\n        FileOutputStream outStream;\n        try\n        {\n            fileObject.createNewFile();\n            inStream = new FileInputStream(secondFileName);\n            outStream = new FileOutputStream(thirdFileName);\n            copyContent(inStream, outStream);\n        }catch(FileNotFoundException e)\n        {\n            e.printStackTrace();\n        }catch(IOException e)\n        {\n            e.printStackTrace();\n        }\n\n    }\n}<\/code><\/pre>\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;\">\u6587\u4ef6\u968f\u673a\u8bbf\u95ee<\/h2>\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;\">\/*\n * RandomFile.java\n *\n *\n * \u6587\u4ef6\u968f\u673a\u8bbf\u95ee\n *\/\npackage study.iostudy;\nimport java.io.*;\n\/*\n * \u6587\u4ef6\u968f\u673a\u8bbf\u95ee\u7684\u65b9\u6cd5\n *\n * void seek(long pos); \u5c06\u6587\u4ef6\u6307\u9488\u79fb\u52a8\u5230\u53c2\u6570\u6307\u5b9a\u7684\u4f4d\u7f6e\u3002\n * long getFilePointer(); \u5f97\u5230\u5f53\u524d\u6587\u4ef6\u6307\u9488\u7684\u4f4d\u7f6e\u3002\n * int skipBytes(int n); \u5c06\u6587\u4ef6\u6307\u9488\u5411\u524d\u79fb\u52a8\u53c2\u6570\u6307\u5b9a\u7684n\u4e2a\u5b57\u8282\u3002\n * String readLine(); \u4ece\u5f53\u524d\u6587\u4ef6\u6307\u5b9a\u4f4d\u7f6e\u8bfb\u53d6\u4e00\u884c\u3002\n *\n *\/\npublic class RandomFile\n{\n    public static void main(String[] args)\n    {\n        String tempStr;\n        int fileLines = 0;\n        long pointerLast = 0;\n        try\n        {\n            RandomAccessFile inObj = new RandomAccessFile(\"d:\\\\mydir\\\\secondFile.txt\", \"rw\");\n            while (inObj.readLine() != null)\n                fileLines++;\n            for (int i =0; i &lt; fileLines \/ 2; i++)\n            {\n                inObj.seek(2 * i);\n                tempStr = inObj.readLine();\n                System.out.println(tempStr);\n            }\n            pointerLast = inObj.getFilePointer();\n        }catch(IOException e)\n        {\n            e.printStackTrace();\n        }\n        try\n        {\n            RandomAccessFile fileObj = new RandomAccessFile(\"d:\\\\mydir\\\\secondFile.txt\", \"rw\");\n            String writeStr = new String(\"Insert a string!\");\n            fileObj.seek(pointerLast);\n            fileObj.writeChars(writeStr);\n        }catch(IOException e)\n        {\n            e.printStackTrace();\n        }\n    }\n}<\/code><\/pre>\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;\">\u5b57\u7b26\u6d41\u5904\u7406<\/h2>\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;\">\/*\n * ProcesserCharacterStream.java\n *\n *\n * \u5b57\u7b26\u6d41\u5904\u7406\n *\n * java.io\u5305\u4e2d\u52a0\u5165\u4e86\u4e13\u95e8\u7528\u4e8e\u5b57\u7b26\u6d41\u5904\u7406\u7684\u7c7b\uff0c\u8fd9\u4e9b\u7c7b\u90fd\u662fReader\u548cWriter\u7c7b\u7684\u5b50\u7c7b\uff0c\n * Reader\u548cWriter\u662f\u4e24\u4e2a\u62bd\u8c61\u7c7b\uff0c\u53ea\u63d0\u4f9b\u4e86\u4e00\u7cfb\u5217\u7528\u4e8e\u5b57\u7b26\u6d41\u5904\u7406\u7684\u63a5\u53e3\uff0c\u4e0d\u80fd\u751f\u6210\u8fd9\n * \u4e24\u4e2a\u7c7b\u7684\u5b9e\u4f8b\u3002\n * java.io\u5305\u4e2d\u7528\u4e8e\u5b57\u7b26\u6d41\u5904\u7406\u7684\u6700\u57fa\u672c\u7684\u7c7b\u662fInputStreamReader\u548cOutputStreamWriter\uff0c\n * \u7528\u6765\u5728\u5b57\u8282\u6d41\u548c\u5b57\u7b26\u6d41\u4e4b\u95f4\u4f5c\u4e3a\u4e2d\u4ecb\u3002\n *\n * \u4e0b\u9762\u662fInputStreamReader\u7c7b\u548cOutputStreamWriter\u7c7b\u7684\u5e38\u7528\u65b9\u6cd5\uff1a\n *\n* public InputStreamReader(InputStream in)\n * \u6839\u636e\u5f53\u524d\u5e73\u53f0\u7f3a\u7701\u7684\u7f16\u7801\u89c4\u8303\uff0c\u57fa\u4e8e\u5b57\u8282\u6d41in\u751f\u6210\u4e00\u4e2a\u8f93\u5165\u5b57\u7b26\u6d41\u3002\n* public InputStreamReader(InputStream in, String sysCode)throws UnSupportedEncodingException\n * \u6309\u7167\u53c2\u6570sysCode\u6307\u5b9a\u7684\u7f16\u7801\u89c4\u8303\uff0c\u57fa\u4e8e\u5b57\u8282\u6d41in\u6784\u9020\u8f93\u5165\u5b57\u7b26\u6d41\uff0c\u5982\u679c\u4e0d\u652f\u6301\u53c2\u6570sysCode\u4e2d\u6307\u5b9a\u7684\u7f16\u7801\u89c4\u8303\uff0c\u5c31\u4f1a\u4ea7\u751f\u5f02\u5e38\u3002\n* public OutputStreamWriter(OutputStream out)\n * \u6839\u636e\u5f53\u524d\u5e73\u53f0\u7f3a\u7701\u7684\u7f16\u7801\u89c4\u8303\uff0c\u57fa\u4e8e\u5b57\u8282\u6d41out\u751f\u6210\u4e00\u4e2a\u8f93\u5165\u5b57\u7b26\u6d41\u3002\n* public OutputStreamWriter(OutputStream out, String sysCode) throws UnsupportedEncodingException\n * \u6309\u7167\u53c2\u6570sysCode\u6307\u5b9a\u7684\u7f16\u7801\u89c4\u8303\uff0c\u57fa\u4e8e\u5b57\u8282\u6d41out\u6784\u9020\u8f93\u5165\u5b57\u7b26\u6d41\uff0c\u5982\u679c\u4e0d\u652f\u6301\u53c2\u6570sysCode\u4e2d\u6307\u5b9a\u7684\u7f16\u7801\u89c4\u8303\uff0c\u5c31\u4f1a\u4ea7\u751f\u5f02\u5e38\u3002\n* public String getEncoding()\n * \u83b7\u5f97\u5f53\u524d\u5b57\u7b26\u6d41\u4f7f\u7528\u7684\u7f16\u7801\u65b9\u5f0f\u3002\n* public void close() throws IOException\n * \u7528\u4e8e\u5173\u95ed\u6d41\u3002\n* public int read() throws IOException\n * \u7528\u4e8e\u8bfb\u53d6\u4e00\u4e2a\u5b57\u7b26\u3002\n* public int read(char[] cbuf, int off, int len)\n * \u7528\u4e8e\u8bfb\u53d6len\u4e2a\u5b57\u7b26\u5230\u6570\u7ec4cbuf\u7684\u7d22\u5f15off\u5904\u3002\n* public void write(char[] cbuf, int off, int len) throws IOException\n * \u5c06\u5b57\u7b26\u6570\u7ec4cbuf\u4e2d\u4ece\u7d22\u5f15off\u5904\u5f00\u59cb\u7684len\u4e2a\u5b57\u7b26\u5199\u5165\u8f93\u51fa\u6d41\u3002\n* public void write(int c) throws IOException\n * \u5c06\u5355\u4e2a\u5b57\u7b26\u5199\u5165\u8f93\u5165\u6d41\u3002\n* public void write(String str, int off, int len) throws IOException\n * \u5c06\u5b57\u7b26\u4e32str\u4e2d\u4ece\u7d22\u5f15off\u4f4d\u7f6e\u5f00\u59cb\u7684ltn\u4e2a\u5b57\u7b26\u5199\u5165\u8f93\u51fa\u6d41\u3002\n *\n * \u6b64\u5916\uff0c\u4e3a\u4e86\u63d0\u9ad8\u5b57\u7b26\u6d41\u5904\u7406\u7684\u6548\u7387\uff0c\u5728Java\u8bed\u8a00\u4e2d\uff0c\u5f15\u5165\u4e86BufferedReader\u548cBufferWriter\u7c7b\uff0c\u8fd9\u4e24\u4e2a\u7c7b\u5bf9\u5b57\u7b26\u6d41\u8fdb\u884c\u5757\u5904\u7406\u3002\n * \u4e24\u4e2a\u7c7b\u7684\u5e38\u7528\u65b9\u6cd5\u5982\u4e0b\uff1a\n * public BufferedReader(Reader in)\n * \u7528\u4e8e\u57fa\u4e8e\u666e\u901a\u5b57\u7b26\u8f93\u5165\u6d41in\u751f\u6210\u76f8\u5e94\u7684\u7f13\u51b2\u6d41\u3002\n * public BufferedReader(Reader in, int bufSize)\n * \u7528\u4e8e\u57fa\u4e8e\u666e\u901a\u5b57\u7b26\u8f93\u5165\u6d41in\u751f\u6210\u76f8\u5e94\u7684\u7f13\u51b2\u6d41\uff0c\u7f13\u51b2\u533a\u5927\u5c0f\u4e3a\u53c2\u6570bufSize\u6307\u5b9a\u3002\n * public BufferedWriter(Writer out)\n * \u7528\u4e8e\u57fa\u4e8e\u666e\u901a\u5b57\u7b26\u8f93\u5165\u6d41out\u751f\u6210\u76f8\u5e94\u7684\u7f13\u51b2\u6d41\u3002\n * public BufferedWriter(Writer out, int bufSize)\n * \u7528\u4e8e\u57fa\u4e8e\u666e\u901a\u5b57\u7b26\u8f93\u5165\u6d41out\u751f\u5728\u76f8\u5e94\u7f13\u51b2\u6d41\uff0c\u7f13\u51b2\u6d41\u5927\u5c0f\u4e3a\u53c2\u6570bufSize\u6307\u5b9a\u3002\n * public String readLine() throws IOException\n * \u7528\u4e8e\u4ece\u8f93\u5165\u6d41\u4e2d\u8bfb\u53d6\u4e00\u884c\u5b57\u7b26\u3002\n * public void newLine() throws IOException\n * \u7528\u4e8e\u5411\u5b57\u7b26\u8f93\u5165\u6d41\u4e2d\u5199\u5165\u4e00\u884c\u7ed3\u675f\u6807\u8bb0\uff0c\u503c\u5f97\u6ce8\u610f\u7684\u662f\uff0c\u8be5\u6807\u8bb0\u4e0d\u662f\u7b80\u5355\u7684\u6362\u884c\u7b26\"\\n\"\uff0c\u800c\u662f\u7cfb\u7edf\u5b9a\u4e49\u7684\u5c5e\u6027line.separator\u3002\n *\/\npackage study.iostudy;\nimport java.io.*;\npublic class ProcesserCharacterStream\n{\n    public static void main(String[] args)\n            throws FileNotFoundException, IOException\n    {\n        String lineStr;\n        FileInputStream fileInStream;\n        InputStreamReader inputReader;\n        BufferedReader bufReader;\n        FileOutputStream fileOutStream;\n        OutputStreamWriter outputWriter;\n        BufferedWriter bufWriter;\n        fileInStream = new FileInputStream(\"d:\\\\mydir\\\\secondFile.txt\");\n        inputReader = new InputStreamReader(fileInStream);\n        bufReader = new BufferedReader(inputReader);\n        System.out.println(\"------------------------------------------------\");\n        System.out.println(\"There are file content before modify:\");\n        while ((lineStr = bufReader.readLine()) != null)\n            System.out.println(lineStr);\n        bufReader.close();\n        inputReader.close();\n        fileInStream.close();\n        fileOutStream = new FileOutputStream(\"d:\\\\mydir\\\\secondFile.txt\");\n        outputWriter = new OutputStreamWriter(fileOutStream);\n        bufWriter = new BufferedWriter(outputWriter);\n        String newStr = new String(\"Modify the file ! \\r\\nThis is a nice thing. \\r\\nWe can write anything.\");\n        bufWriter.write(newStr, 0, newStr.length());\n        System.out.println(newStr);\n        bufWriter.close();\n        outputWriter.close();\n        fileOutStream.close();\n        fileInStream = new FileInputStream(\"d:\\\\mydir\\\\secondFile.txt\");\n        inputReader = new InputStreamReader(fileInStream);\n        bufReader = new BufferedReader(inputReader);\n        System.out.println(\"------------------------------------------------\");\n        System.out.println(\"There are file content after modify:\");\n        while ((lineStr = bufReader.readLine()) != null)\n            System.out.println(lineStr);\n        bufReader.close();\n        inputReader.close();\n        fileInStream.close();\n    }\n}<\/code><\/pre>\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;\">\u63a5\u6536\u952e\u76d8\u8f93\u5165\u6570\u636e<\/h2>\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;\">\/*\n * OutputKeyPress.java\n *\n *\n * \u63a5\u6536\u952e\u76d8\u8f93\u5165\u6570\u636e\n *\/\npackage study.iostudy;\nimport java.io.*;\npublic class OutputKeyPress\n{\n    public static void main(String[] args)\n    {\n        System.out.println(\"This is a example about acceptance of keyboard.\");\n        String tempStr = \"0\";\n        try\n        {\n            InputStreamReader inputReader;\n            BufferedReader bufReader;\n            inputReader = new InputStreamReader(System.in);\n            bufReader = new BufferedReader(inputReader);\n            tempStr = bufReader.readLine();\n            System.out.println(\"Input num is: \" + tempStr);\n        }catch(IOException e)\n        {\n            e.printStackTrace();\n        }\n        int n = Integer.parseInt(tempStr);\n        int nultiNum = 1;\n        for (int i =1; i &lt;= n; i++)\n        {\n            nultiNum *= i;\n        }\n        System.out.println(\"multiply of input number is: \" + nultiNum);\n    }   \n}<\/code><\/pre>\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;\">\u8fc7\u6ee4\u6d41<\/h2>\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;\">\/*\n * FilterStream.java\n *\n * \u8fc7\u6ee4\u6d41\n *\n * \u8fc7\u6ee4\u6d41\u5728\u8bfb\/\u5199\u6570\u636e\u7684\u540c\u65f6\u53ef\u4ee5\u5bf9\u6570\u636e\u8fdb\u884c\u5904\u7406\uff0c\u5e76\u63d0\u4f9b\u4e86\u540c\u6b65\u673a\u5236\uff0c\n * \u8fd9\u6837\u5728\u540c\u4e00\u65f6\u523b\u53ea\u6709\u4e00\u4e2a\u7ebf\u7a0b\u53ef\u4ee5\u8bbf\u95ee\u4e00\u4e2aI\/O\u6d41\u3002\u5728java.io\u5305\u4e2d\uff0c\n * FilterInputStream\u548cFilterOutputStream\u7c7b\u662f\u6240\u6709\u8fc7\u6ee4\u8f93\u5165\u6d41\u548c\n * \u8f93\u51fa\u6d41\u7684\u7236\u7c7b\uff0c\u5b83\u4eec\u662f\u62bd\u8c61\u7c7b\uff0c\u672c\u8eab\u4e0d\u80fd\u751f\u6210\u4efb\u4f55\u5b9e\u4f8b\uff0c\u5728\u8fd9\u4e24\u4e0a\u7c7b\n * \u4e4b\u4e0b\uff0c\u5206\u522b\u5b9e\u73b0\u4e86\u51e0\u7269\u7279\u6b8a\u7684\u8fc7\u6ee4\u8f93\u5165\u6d41\u548c\u8f93\u51fa\u6d41\uff0c\u5229\u7528\u8fd9\u4e9b\u7279\u6b8a\u8f93\n * \u5165\u6d41\u548c\u8f93\u51fa\u6d41\u7684\u5b9e\u4f8b\u53ef\u4ee5\u8fdb\u884c\u6d41\u5904\u7406\u3002\n *\n * \u4e0b\u9762\u4ecb\u7ecd\u51e0\u4e2a\u8fc7\u6ee4\u8f93\u5165\u6d41\u548c\u8f93\u51fa\u6d41\u7684\u5b50\u7c7b\uff1a\n *\n * BufferedInputStream \u548c BufferedOutputStream\n * \u8fd9\u4e24\u4e2a\u7c7b\u5b9e\u73b0\u4e86\u5e26\u7f13\u51b2\u7684\u8fc7\u6ee4\u6d41\uff0c\u5c06\u4efb\u610f\u7684\u8f93\u5165\u6d41\u548c\u8f93\u51fa\u6d41\u7ed1\u5b9a\u5230\u7f13\n * \u51b2\u6d41\u4e0a\u5c31\u4f1a\u63d0\u9ad8\u6027\u80fd\u3002\n * \u5bf9\u4e8eBufferedInputStream\u7c7b\uff0c\u5f53\u7cfb\u7edf\u8bfb\u53d6\u6570\u636e\u65f6\uff0c\u6570\u636e\u6309\u5757\u8bfb\u5165\u7f13\n * \u51b2\u533a\uff0c\u968f\u540e\u8bfb\u64cd\u4f5c\u76f4\u63a5\u8bbf\u95ee\u7f13\u51b2\u533a\u3002\u4f7f\u7528BufferedOutputStream\u8fdb\u884c\n * \u8f93\u51fa\u65f6\uff0c\u6570\u636e\u9996\u5148\u5199\u5165\u7f13\u51b2\u533a\uff0c\u5f53\u7f13\u51b2\u533a\u6ee1\u65f6\uff0c\u7f13\u51b2\u533a\u4e2d\u7684\u6570\u636e\u5199\u5165\n * \u8fde\u63a5\u7684\u8f93\u51fa\u6d41\uff0cBufferedOutputStream\u7c7b\u63d0\u4f9b\u7684\u65b9\u6cd5flush()\u53ef\u4ee5\u5f3a\n * \u5236\u5c06\u7f13\u51b2\u533a\u7684\u5185\u5bb9\u5168\u90e8\u5199\u5165\u8f93\u51fa\u6d41\u3002\n *\n * DataInputStream \u548c DataOutputStream\n * \u8fd9\u4e24\u4e2a\u7c7b\u4e0d\u4ec5\u80fd\u8bfb\u5199\u6570\u636e\u6d41\uff0c\u800c\u4e14\u80fd\u8bfb\u5199\u5404\u79cd\u5404\u6837\u7684Java\u8bed\u8a00\u672c\u8eab\u56fa\n * \u6709\u7684\u6570\u636e\u7c7b\u578b\uff0c\u5982int\u3001float\u7b49\u3002\n *\n * PushbackInputStream\n * PushbackInputStream\u7c7b\u63d0\u4f9b\u4e86\u65b9\u6cd5\u5c06\u521a\u8bfb\u8fc7\u7684\u5b57\u8282\u9000\u56de\u5230\u8f93\u5165\u6d41\u4e2d\uff0c\n * \u540e\u9762\u7684\u5185\u5bb9\u5c31\u53ef\u4ee5\u7528\u5230\u8be5\u5b57\u8282\u3002\n **\/\n\npackage study.iostudy;\nimport java.io.*;\npublic class FilterStream\n{\n    public static void main(String[] args)\n    {\n        try\n        {\n            FileInputStream inStream;\n            FileOutputStream outStream;\n            BufferedInputStream bufInObj;\n            BufferedOutputStream bufOutObj;\n            DataInputStream dataInObj;\n            PushbackInputStream pushObj;\n            byte[] tempBuf = new byte[1024];\n            int copyLen;\n            inStream = new FileInputStream(\"d:\\\\mydir\\\\secondFile.txt\");\n            outStream = new FileOutputStream(\"d:\\\\mydir\\\\thirdFile.txt\");\n            bufInObj = new BufferedInputStream(inStream);\n            bufOutObj = new BufferedOutputStream(outStream);\n            dataInObj = new DataInputStream(inStream);\n            System.out.println(dataInObj.readBoolean());\n            while ((copyLen = bufInObj.read(tempBuf, 0, 1024)) != -1)\n            {\n                String copyStr = new String(tempBuf);\n                System.out.println(copyStr);\n                bufOutObj.write(tempBuf, 0, copyLen);\n                bufOutObj.flush();\n            }\n            int pushData;\n            byte[] pushByte = {'o', 'k'};\n            pushObj = new PushbackInputStream(\n                    new FileInputStream(\"d:\\\\mydir\\\\thirdFile.txt\"), 1000);\n            while ((pushData = pushObj.read()) != -1)\n            {\n                if (Character.isLetter((char)pushData))\n                {\n                    System.out.print((char)pushData);\n                }\n                else\n                {\n                    System.out.println();\n                    pushObj.unread(pushByte);\n                }\n            }\n        }catch(FileNotFoundException e)\n        {\n            System.out.println(\"File not found or persission denied.\");\n        }catch(IOException e)\n        {\n            System.out.println(\"error:\" + e);\n        }\n    }\n}\n    <\/code><\/pre>\n<p style=\"margin: 1em 0px;\">\u5728\u4e0a\u9762\u7684\u7a0b\u5e8f\u4e2d\uff0c\u6211\u4eec\u9996\u5148\u58f0\u660e\u4e86FileInputStream\u7c7b\u5bf9\u8c61inStream\u548c FileOutputStream\u7c7b\u7684\u5bf9\u8c61outStream\uff0c\u63a5\u7740\u58f0\u660e\u4e86BufferInputStream \u7c7b\u5bf9\u8c61bufObj\u3001BufferedOutputStream\u7c7b\u5bf9\u8c61bufOutObj\u3001 DataInputStream\u7c7b\u5bf9\u8c61dataInObj\u4ee5\u53caPushbackInputStream\u7c7b\u5bf9\u8c61pushObj\uff0c \u5728try\u4ee3\u7801\u5757\u4e2d\u5bf9\u4e0a\u9762\u8fd9\u4e9b\u5bf9\u8c61\u8fdb\u884c\u521d\u59cb\u5316\uff0c\u7a0b\u5e8f\u7684\u76ee\u7684\u662f\u901a\u8fc7BufferedInputStream \u7c7b\u5bf9\u8c61bufInObj\u548cBufferedOutputStream\u7c7b\u5bf9\u8c61bufOutObj\u5c06secondFile.txt \u6587\u4ef6\u4e2d\u5185\u5bb9\u8f93\u51fa\u5230\u5c4f\u5e55\uff0c\u5e76\u5c06\u8be5\u6587\u4ef6\u7684\u5185\u5bb9\u5199\u5165thirdFile.txt\u6587\u4ef6\u4e2d\uff0c\u503c\u5f97\u6ce8\u610f\u7684\u662f\uff0c \u5c06secondFile.txt\u6587\u4ef6\u4e2d\u7684\u5185\u5bb9\u8f93\u51fa\u4e4b\u524d\uff0c\u7a0b\u5e8f\u4e2d\u4f7f\u7528 &#8220;System.out.println(dataInObj.readBoolean());&#8221; \u8bed\u53e5\u6839\u636ereadBoolean()\u7ed3\u679c \u8f93\u51fa\u4e86true\uff0c\u800csecondFile.txt\u6587\u4ef6\u5f00\u59cb\u5185\u5bb9\u4e3a\u201cModify\u201d\uff0c\u548c\u4e00\u4e2a\u5b57\u7b26\u4e3aM\uff0c \u56e0\u6b64\u8f93\u51fa\u7684\u6587\u4ef6\u5185\u5bb9\u6ca1\u6709\u201cM\u201d\u5b57\u7b26\uff0cthirdFile.txt\u6587\u4ef6\u4e2d\u4e5f\u6bd4secondFile.txt \u6587\u4ef6\u5c11\u7b2c\u4e00\u4e2a\u5b57\u7b26\u201cM\u201d\u3002\u968f\u540e\uff0c\u901a\u8fc7PushbackInputStream\u7c7b\u5bf9\u8c61pushObj\u8bfb\u53d6 thirdFile.txt\u6587\u4ef6\u4e2d\u7684\u5185\u5bb9\uff0c\u8f93\u51fa\u8bfb\u5230\u7684\u5b57\u7b26\uff0c\u5f53\u8bfb\u5230\u7684\u4e0d\u662f\u5b57\u7b26\uff0c\u8f93\u51fa\u56de\u8f66\uff0c\u5c06\u5b57\u7b26 \u6570\u7ec4pushByte\u5199\u56de\u5230thirdFile.txt\u6587\u4ef6\u4e2d\uff0c\u4e5f\u5c31\u662f\u201cok\u201d\u5199\u56de\u6587\u4ef6\u4e2d\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;\">\u987a\u5e8f\u8f93\u5165\u6d41<\/h2>\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;\">\/*\n * SequenceStream.java\n *\n *\n * \u987a\u5e8f\u8f93\u5165\u6d41\n *\n * java.io\u5305\u4e2d\u63d0\u4f9b\u4e86SequenceInputStream\u7c7b\uff0c\u7528\u4e8e\u5c06\u591a\u4e2a\u8f93\u5165\u6d41\u987a\u5e8f\u8fde\u63a5\u8d77\u6765\uff0c\n * \u4f7f\u5b83\u4eec\u770b\u8d77\u6765\u5c31\u50cf\u4e00\u4e2a\u8f83\u957f\u7684\u6d41\u3002\n *\/\npackage study.iostudy;\nimport java.io.*;\npublic class SequenceStream\n{\n    public static void main(String[] args)\n    {\n        FileInputStream fileStream1, fileStream2;\n        try\n        {\n            String allStr;\n            fileStream1 = new FileInputStream(\"d:\\\\mydir\\\\secondFile.txt\");\n            fileStream2 = new FileInputStream(\"d:\\\\mydir\\\\thirdFile.txt\");\n            SequenceInputStream seqStream = new SequenceInputStream(\n                    fileStream1, fileStream2);\n            BufferedInputStream bufObj = new BufferedInputStream(seqStream);\n            byte[] bufByte = new byte[1024];\n            while (bufObj.read(bufByte, 0, 1024) != -1)\n            {\n                String tempStr = new String(bufByte);\n                System.out.println(tempStr);\n            }\n        }catch(FileNotFoundException e)\n        {\n            System.out.println(\"File not found or no permission.\");\n        }catch(IOException e)\n        {\n            System.out.println(\"error:\" + e);\n        }\n    }\n}<\/code><\/pre>\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;\">\u5bf9\u8c61\u4e32\u884c\u5316<\/h2>\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;\">\/*\n * SerializableObject.java\n *\n * \u5bf9\u8c61\u4e32\u884c\u5316\n * \u3000\u3000\u5bf9\u8c61\u901a\u8fc7\u5199\u51fa\u63cf\u8ff0\u81ea\u5df1\u72b6\u6001\u7684\u6570\u503c\u6765\u8bb0\u5f55\u81ea\u5df1\uff0c\u8fd9\u4e2a\u8fc7\u7a0b\u53eb\u505a\u5bf9\u8c61\u4e32\u884c\u5316\u3002\u5bf9\u8c61\u7684\u5bff\u547d\u901a\n * \u5e38\u662f\u968f\u7740\u751f\u6210\u8be5\u5bf9\u8c61\u7684\u7a0b\u5e8f\u7684\u7ec8\u6b62\u800c\u7ec8\u6b62\uff0c\u5728\u6709\u4e9b\u60c5\u51b5\u4e0b\uff0c\u9700\u8981\u5c06\u5bf9\u8c61\u7684\u72b6\u6001\u4fdd\u5b58\u4e0b\u6765\uff0c\u7136\u540e\n * \u5728\u5fc5\u8981\u7684\u65f6\u5019\u5c06\u5bf9\u8c61\u6062\u590d\uff0c\u503c\u5f97\u6ce8\u610f\u7684\u662f\uff0c\u5982\u679c\u53d8\u91cf\u662f\u53e6\u4e00\u4e2a\u5bf9\u8c61\u7684\u5f15\u7528\uff0c\u5219\u5f15\u7528\u7684\u5bf9\u8c61\u4e5f\u8981\n * \u4e32\u884c\u5316\uff0c\u4e32\u884c\u5316\u662f\u4e00\u4e2a\u9012\u5f52\u7684\u8fc7\u7a0b\uff0c\u53ef\u80fd\u4f1a\u6d89\u53ca\u5230\u4e00\u4e2a\u590d\u6742\u6811\u7ed3\u6784\u7684\u4e32\u884c\u5316\uff0c\u6bd4\u5982\u5305\u62ec\u539f\u6709\u5bf9\n * \u8c61\uff0c\u5bf9\u8c61\u7684\u5bf9\u8c61\u7b49\u3002\n * \u3000\u3000\u5728java.io\u5305\u4e2d\uff0c\u63a5\u53e3Serializable\u662f\u5b9e\u73b0\u5bf9\u8c61\u4e32\u884c\u5316\u7684\u5de5\u5177,\u53ea\u6709\u5b9e\u73b0\u4e86Serializable\n * \u7684\u5bf9\u8c61\u624d\u53ef\u4ee5\u88ab\u4e32\u884c\u5316\u3002Serializable\u63a5\u53e3\u4e2d\u6ca1\u6709\u4efb\u4f55\u7684\u65b9\u6cd5\uff0c\u5f53\u4e00\u4e2a\u7c7b\u58f0\u660e\u5b9e\u73b0Seriali-\n * zable\u63a5\u53e3\u65f6\uff0c\u53ea\u662f\u8868\u660e\u8be5\u7c7b\u9075\u5faa\u4e32\u884c\u5316\u534f\u8bae\uff0c\u800c\u4e0d\u9700\u8981\u5b9e\u73b0\u4efb\u4f55\u7279\u6b8a\u7684\u65b9\u6cd5\u3002\n * \u3000\u3000\u5728\u8fdb\u884c\u5bf9\u8c61\u4e32\u884c\u5316\u65f6\uff0c\u9700\u8981\u6ce8\u610f\u5c06\u4e32\u884c\u5316\u7684\u5bf9\u8c61\u548c\u8f93\u5165\u3001\u8f93\u51fa\u6d41\u8054\u7cfb\u8d77\u6765\uff0c\u9996\u5148\u901a\u8fc7\u5bf9\n * \u8c61\u8f93\u51fa\u6d41\u5c06\u5bf9\u8c61\u72b6\u6001\u4fdd\u5b58\u4e0b\u6765\uff0c\u7136\u540e\u901a\u8fc7\u5bf9\u8c61\u8f93\u5165\u6d41\u5c06\u5bf9\u8c61\u72b6\u6001\u6062\u590d\u3002\n *\/\n\npackage study.iostudy;\n\nimport java.io.*;\n\nclass Book implements Serializable\n{\n    String isbn;\n    String name;\n    int page;\n    String type;\n    public Book(String isbn, String name, int page, String type)\n    {\n        this.isbn = isbn;\n        this.name = name;\n        this.page = page;\n        this.type = type;\n    }\n}\n\npublic class SerializableObject implements Serializable\n{\n    public static void main(String[] args)\n            throws IOException, ClassNotFoundException\n    {\n        Book bookObj = new Book(\"7-02-016450-1\", \"Java\", 218, \"programming\");\n        FileOutputStream fileOStream = new FileOutputStream(\"temp.ser\");\n        ObjectOutputStream objOutStream = new ObjectOutputStream(fileOStream);\n        try\n        {\n            objOutStream.writeObject(bookObj);\n            objOutStream.close();\n        }catch(IOException e)\n        {\n            e.printStackTrace();\n        }\n        bookObj = null;\n        FileInputStream fileInStream = new FileInputStream(\"temp.ser\");\n        ObjectInputStream objInStream = new ObjectInputStream(fileInStream);\n        try\n        {\n            bookObj = (Book)objInStream.readObject();\n            objInStream.close();\n        }catch(IOException e)\n        {\n            e.printStackTrace();\n        }\n        System.out.println(\"------------------------------------------------\");\n        System.out.println(\"There are information about book:\");\n        System.out.println(\"ISBN Number: \" + bookObj.isbn);\n        System.out.println(\"Book Name: \" + bookObj.name);\n        System.out.println(\"Book Page: \" + bookObj.page);\n        System.out.println(\"Book Type: \" + bookObj.type);\n    }\n}<\/code><\/pre>\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\uff1aJava IO \u5148\u6293\u4f4f File \u4e0e\u5b57\u8282\/\u5b57\u7b26\u6d41\u4e24\u6761\u7ebf\uff0c\u518d\u7528\u7f13\u51b2\u3001\u8fc7\u6ee4\u3001\u987a\u5e8f\u6d41\u548c\u5bf9\u8c61\u4e32\u884c\u5316\u628a\u8bfb\u5199\u573a\u666f\u8865\u9f50\u3002<\/strong><\/p>\n<\/blockquote>\n<\/section>\n","protected":false},"excerpt":{"rendered":"<p>\u8fd9\u7bc7\u662f Java IO \u5b66\u4e60\u7b14\u8bb0\u52a0\u4ee3\u7801\uff1a\u4ece File \u5bf9\u8c61\u7684\u751f\u6210\u3001\u521b\u5efa\u3001\u6539\u540d\u548c\u5c5e\u6027\u6d4b\u8bd5\uff0c\u8bb2\u5230\u62f7\u8d1d\u3001\u968f\u673a\u8bbf\u95ee\u3001\u5b57 [&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\/263"}],"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=263"}],"version-history":[{"count":3,"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=\/wp\/v2\/posts\/263\/revisions"}],"predecessor-version":[{"id":326,"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=\/wp\/v2\/posts\/263\/revisions\/326"}],"wp:attachment":[{"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=263"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=263"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=263"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}