{"id":260,"date":"2023-12-11T16:20:38","date_gmt":"2023-12-11T08:20:38","guid":{"rendered":"http:\/\/ericw.top\/?p=260"},"modified":"2023-12-11T16:20:38","modified_gmt":"2023-12-11T08:20:38","slug":"java-%e5%ad%97%e8%8a%82%e6%b5%81","status":"publish","type":"post","link":"http:\/\/ericw.top\/?p=260","title":{"rendered":"JAVA \u5b57\u8282\u6d41"},"content":{"rendered":"<h1 id=\"toc-0\">JAVA \u5b57\u8282\u6d41<\/h1>\n<h2 id=\"toc-1\">\u4ec0\u4e48\u662f\u5b57\u8282\u6d41\uff1f<\/h2>\n<p><strong>\u5b57\u8282\u6d41\u662fJava\u4e2d\u7528\u4e8e\u5904\u7406\u4e8c\u8fdb\u5236\u6570\u636e\u7684\u4e00\u79cd\u673a\u5236\u3002<\/strong>\u5b83\u4eec\u4e3b\u8981\u7528\u4e8e\u8bfb\u53d6\u548c\u5199\u5165\u5b57\u8282\uff088\u4f4d\uff09\u6570\u636e\uff0c\u800c\u4e0d\u8003\u8651\u6570\u636e\u7684\u5185\u5bb9\u3002\u5728\u5904\u7406\u6587\u4ef6\u3001\u7f51\u7edc\u8fde\u63a5\u548c\u5176\u4ed6I\/O\u64cd\u4f5c\u65f6\uff0c\u5b57\u8282\u6d41\u662f\u5fc5\u4e0d\u53ef\u5c11\u7684\u3002<\/p>\n<p>\u5b57\u8282\u6d41\u5206\u4e3a\u4e24\u79cd\u7c7b\u578b\uff1a<\/p>\n<ol>\n<li><strong>\u8f93\u5165\u5b57\u8282\u6d41\uff08Input Byte Stream\uff09<\/strong>\uff1a\u7528\u4e8e\u4ece\u5916\u90e8\u6570\u636e\u6e90\uff08\u5982\u6587\u4ef6\u6216\u7f51\u7edc\u8fde\u63a5\uff09\u8bfb\u53d6\u6570\u636e\u5230Java\u7a0b\u5e8f\u4e2d\u3002<\/li>\n<li><strong>\u8f93\u51fa\u5b57\u8282\u6d41\uff08Output Byte Stream\uff09<\/strong>\uff1a\u7528\u4e8e\u5c06\u6570\u636e\u4eceJava\u7a0b\u5e8f\u5199\u5165\u5916\u90e8\u6570\u636e\u6e90\u3002<\/li>\n<\/ol>\n<h3 id=\"toc-2\">\u8f93\u5165\u5b57\u8282\u6d41<\/h3>\n<h4 id=\"toc-3\">FileInputStream<\/h4>\n<p><code class=\"prettyprint\" >FileInputStream<\/code> \u662f\u7528\u4e8e\u4ece\u6587\u4ef6\u4e2d\u8bfb\u53d6\u5b57\u8282\u6570\u636e\u7684\u7c7b\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u7b80\u5355\u7684\u793a\u4f8b\uff0c\u6f14\u793a\u5982\u4f55\u4f7f\u7528 <code class=\"prettyprint\" >FileInputStream<\/code> \u8bfb\u53d6\u6587\u4ef6\uff1a<\/p>\n<pre><code class=\"prettyprint\"  class=\"language-java\">import java.io.FileInputStream;\nimport java.io.IOException;\n\npublic class FileInputStreamExample {\n    public static void main(String[] args) {\n        try {\n            FileInputStream fileInputStream = new FileInputStream(&quot;example.txt&quot;);\n            int data;\n            while ((data = fileInputStream.read()) != -1) {\n                System.out.print((char) data);\n            }\n            fileInputStream.close();\n        } catch (IOException e) {\n            e.printStackTrace();\n        }\n    }\n}<\/code><\/pre>\n<p>\u5728\u4e0a\u8ff0\u793a\u4f8b\u4e2d\uff0c\u6211\u4eec\u9996\u5148\u521b\u5efa\u4e00\u4e2a <code class=\"prettyprint\" >FileInputStream<\/code> \u6765\u6253\u5f00\u6587\u4ef6 \u201cexample.txt\u201d\uff0c\u7136\u540e\u4f7f\u7528 <code class=\"prettyprint\" >read()<\/code> \u65b9\u6cd5\u9010\u5b57\u8282\u8bfb\u53d6\u6587\u4ef6\u5185\u5bb9\u3002\u8bfb\u53d6\u7684\u6570\u636e\u4ee5\u6574\u6570\u5f62\u5f0f\u8fd4\u56de\uff0c\u6211\u4eec\u5c06\u5176\u8f6c\u6362\u4e3a\u5b57\u7b26\u5e76\u6253\u5370\u51fa\u6765\u3002<\/p>\n<h4 id=\"toc-4\">BufferedInputStream<\/h4>\n<p><code class=\"prettyprint\" >BufferedInputStream<\/code> \u662f <code class=\"prettyprint\" >FileInputStream<\/code> \u7684\u88c5\u9970\u5668\u7c7b\uff0c\u5b83\u63d0\u4f9b\u4e86\u7f13\u51b2\u529f\u80fd\uff0c\u53ef\u4ee5\u63d0\u9ad8\u6587\u4ef6\u8bfb\u53d6\u7684\u6548\u7387\u3002\u4f7f\u7528 <code class=\"prettyprint\" >BufferedInputStream<\/code> \u53ef\u4ee5\u51cf\u5c11\u9891\u7e41\u7684\u78c1\u76d8\u8bbf\u95ee\u3002<\/p>\n<p>\u4ee5\u4e0b\u662f\u4e00\u4e2a\u4f7f\u7528 <code class=\"prettyprint\" >BufferedInputStream<\/code> \u7684\u793a\u4f8b\uff1a<\/p>\n<pre><code class=\"prettyprint\"  class=\"language-java\">import java.io.BufferedInputStream;\nimport java.io.FileInputStream;\nimport java.io.IOException;\n\npublic class BufferedInputStreamExample {\n    public static void main(String[] args) {\n        try {\n            FileInputStream fileInputStream = new FileInputStream(&quot;example.txt&quot;);\n            BufferedInputStream bufferedInputStream = new BufferedInputStream(fileInputStream);\n            int data;\n            while ((data = bufferedInputStream.read()) != -1) {\n                System.out.print((char) data);\n            }\n            bufferedInputStream.close();\n        } catch (IOException e) {\n            e.printStackTrace();\n        }\n    }\n}<\/code><\/pre>\n<h4 id=\"toc-5\">DataInputStream<\/h4>\n<p><code class=\"prettyprint\" >DataInputStream<\/code> \u662f\u7528\u4e8e\u4ece\u8f93\u5165\u5b57\u8282\u6d41\u4e2d\u8bfb\u53d6\u57fa\u672c\u6570\u636e\u7c7b\u578b\u7684\u7c7b\uff0c\u5982\u6574\u6570\u3001\u6d6e\u70b9\u6570\u7b49\u3002\u8fd9\u5bf9\u4e8e\u8bfb\u53d6\u4e8c\u8fdb\u5236\u6570\u636e\u975e\u5e38\u6709\u7528\u3002<\/p>\n<p>\u4ee5\u4e0b\u662f\u4e00\u4e2a\u4f7f\u7528 <code class=\"prettyprint\" >DataInputStream<\/code> \u8bfb\u53d6\u6574\u6570\u7684\u793a\u4f8b\uff1a<\/p>\n<pre><code class=\"prettyprint\"  class=\"language-java\">import java.io.DataInputStream;\nimport java.io.FileInputStream;\nimport java.io.IOException;\n\npublic class DataInputStreamExample {\n    public static void main(String[] args) {\n        try {\n            FileInputStream fileInputStream = new FileInputStream(&quot;data.bin&quot;);\n            DataInputStream dataInputStream = new DataInputStream(fileInputStream);\n            int number = dataInputStream.readInt();\n            System.out.println(&quot;Read number: &quot; + number);\n            dataInputStream.close();\n        } catch (IOException e) {\n            e.printStackTrace();\n        }\n    }\n}<\/code><\/pre>\n<h3 id=\"toc-6\">\u8f93\u51fa\u5b57\u8282\u6d41<\/h3>\n<h4 id=\"toc-7\">FileOutputStream<\/h4>\n<p><code class=\"prettyprint\" >FileOutputStream<\/code> \u662f\u7528\u4e8e\u5c06\u5b57\u8282\u6570\u636e\u5199\u5165\u6587\u4ef6\u7684\u7c7b\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u793a\u4f8b\uff0c\u6f14\u793a\u5982\u4f55\u4f7f\u7528 <code class=\"prettyprint\" >FileOutputStream<\/code> \u5199\u5165\u6587\u4ef6\uff1a<\/p>\n<pre><code class=\"prettyprint\"  class=\"language-java\">import java.io.FileOutputStream;\nimport java.io.IOException;\n\npublic class FileOutputStreamExample {\n    public static void main(String[] args) {\n        try {\n            FileOutputStream fileOutputStream = new FileOutputStream(&quot;output.txt&quot;);\n            String text = &quot;Hello, Java Byte Streams!&quot;;\n            byte[] bytes = text.getBytes();\n            fileOutputStream.write(bytes);\n            fileOutputStream.close();\n        } catch (IOException e) {\n            e.printStackTrace();\n        }\n    }\n}<\/code><\/pre>\n<p>\u5728\u4e0a\u8ff0\u793a\u4f8b\u4e2d\uff0c\u6211\u4eec\u9996\u5148\u521b\u5efa\u4e00\u4e2a FileOutputStream \u6765\u6307\u5b9a\u8f93\u51fa\u6587\u4ef6 \u201coutput.txt\u201d\uff0c\u7136\u540e\u5c06\u5b57\u7b26\u4e32\u8f6c\u6362\u4e3a\u5b57\u8282\u6570\u7ec4\u5e76\u4f7f\u7528 write() \u65b9\u6cd5\u5199\u5165\u6587\u4ef6\u3002<\/p>\n<p>BufferedOutputStream<br \/>\nBufferedOutputStream \u662f FileOutputStream \u7684\u88c5\u9970\u5668\u7c7b\uff0c\u5b83\u63d0\u4f9b\u4e86\u7f13\u51b2\u529f\u80fd\uff0c\u53ef\u4ee5\u63d0\u9ad8\u6587\u4ef6\u5199\u5165\u7684\u6548\u7387\u3002<\/p>\n<p>\u4ee5\u4e0b\u662f\u4e00\u4e2a\u4f7f\u7528 BufferedOutputStream \u7684\u793a\u4f8b\uff1a<\/p>\n<pre><code class=\"prettyprint\"  class=\"language-java\">import java.io.BufferedOutputStream;\nimport java.io.FileOutputStream;\nimport java.io.IOException;\n\npublic class BufferedOutputStreamExample {\n    public static void main(String[] args) {\n        try {\n            FileOutputStream fileOutputStream = new FileOutputStream(&quot;output.txt&quot;);\n            BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(fileOutputStream);\n            String text = &quot;Hello, Buffered Streams!&quot;;\n            byte[] bytes = text.getBytes();\n            bufferedOutputStream.write(bytes);\n            bufferedOutputStream.close();\n        } catch (IOException e) {\n            e.printStackTrace();\n        }\n    }\n}<\/code><\/pre>\n<h4 id=\"toc-8\">DataOutputStream<\/h4>\n<p><code class=\"prettyprint\" >DataOutputStream<\/code> \u662f\u7528\u4e8e\u5c06\u57fa\u672c\u6570\u636e\u7c7b\u578b\u5199\u5165\u8f93\u51fa\u5b57\u8282\u6d41\u7684\u7c7b\uff0c\u4e0e <code class=\"prettyprint\" >DataInputStream<\/code> \u76f8\u5bf9\u5e94\u3002\u8fd9\u5bf9\u4e8e\u5c06\u4e8c\u8fdb\u5236\u6570\u636e\u5199\u5165\u6587\u4ef6\u975e\u5e38\u6709\u7528\u3002<\/p>\n<p>\u4ee5\u4e0b\u662f\u4e00\u4e2a\u4f7f\u7528 <code class=\"prettyprint\" >DataOutputStream<\/code> \u5199\u5165\u6574\u6570\u7684\u793a\u4f8b\uff1a<\/p>\n<pre><code class=\"prettyprint\"  class=\"language-java\">import java.io.DataOutputStream;\nimport java.io.FileOutputStream;\nimport java.io.IOException;\n\npublic class DataOutputStreamExample {\n    public static void main(String[] args) {\n        try {\n            FileOutputStream fileOutputStream = new FileOutputStream(&quot;data.bin&quot;);\n            DataOutputStream dataOutputStream = new DataOutputStream(fileOutputStream);\n            int number = 42;\n            dataOutputStream.writeInt(number);\n            dataOutputStream.close();\n        } catch (IOException e) {\n            e.printStackTrace();\n        }\n    }\n}<\/code><\/pre>\n<h2 id=\"toc-9\">\u6587\u4ef6\u5904\u7406\u7684\u5f02\u5e38\u5904\u7406<\/h2>\n<p>\u5728\u4e0a\u8ff0\u793a\u4f8b\u4e2d\uff0c\u6211\u4eec\u4f7f\u7528\u4e86\u5f02\u5e38\u5904\u7406\u6765\u5904\u7406\u53ef\u80fd\u51fa\u73b0\u7684\u9519\u8bef\u60c5\u51b5\u3002\u5728\u5b9e\u9645\u5e94\u7528\u4e2d\uff0c\u786e\u4fdd\u9002\u5f53\u5904\u7406\u6587\u4ef6\u64cd\u4f5c\u4e2d\u7684\u5f02\u5e38\u975e\u5e38\u91cd\u8981\uff0c\u4ee5\u907f\u514d\u7a0b\u5e8f\u5d29\u6e83\u3002<\/p>\n<h2 id=\"toc-10\">JAVA\u5b57\u8282\u6d41\u7684\u66f4\u591a\u7528\u6cd5<\/h2>\n<p><strong>1.\u590d\u5236\u6587\u4ef6<\/strong><\/p>\n<p>\u5c06\u4e00\u4e2a\u6587\u4ef6\u7684\u5185\u5bb9\u590d\u5236\u5230\u53e6\u4e00\u4e2a\u6587\u4ef6\u662f\u5e38\u89c1\u7684\u6587\u4ef6\u64cd\u4f5c\u4e4b\u4e00\u3002\u4f60\u53ef\u4ee5\u4f7f\u7528Java\u5b57\u8282\u6d41\u6765\u8f7b\u677e\u5b9e\u73b0\u6587\u4ef6\u590d\u5236\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u793a\u4f8b\uff1a<\/p>\n<pre><code class=\"prettyprint\"  class=\"language-java\">import java.io.*;\n\npublic class FileCopyExample {\n    public static void main(String[] args) {\n        try (FileInputStream inputStream = new FileInputStream(&quot;source.txt&quot;);\n             FileOutputStream outputStream = new FileOutputStream(&quot;destination.txt&quot;)) {\n\n            byte[] buffer = new byte[1024];\n            int bytesRead;\n            while ((bytesRead = inputStream.read(buffer)) != -1) {\n                outputStream.write(buffer, 0, bytesRead);\n            }\n            System.out.println(&quot;\u6587\u4ef6\u590d\u5236\u5b8c\u6210\u3002&quot;);\n        } catch (IOException e) {\n            e.printStackTrace();\n        }\n    }\n}<\/code><\/pre>\n<p>\u5728\u4e0a\u8ff0\u793a\u4f8b\u4e2d\uff0c\u6211\u4eec\u4f7f\u7528 FileInputStream \u4ece\u6e90\u6587\u4ef6\u8bfb\u53d6\u6570\u636e\uff0c\u7136\u540e\u4f7f\u7528 FileOutputStream \u5c06\u6570\u636e\u5199\u5165\u76ee\u6807\u6587\u4ef6\u3002\u901a\u8fc7\u4e0d\u65ad\u8bfb\u53d6\u548c\u5199\u5165\u6570\u636e\u5757\uff0c\u53ef\u4ee5\u6709\u6548\u5730\u590d\u5236\u5927\u578b\u6587\u4ef6\u3002<\/p>\n<p><strong>2.\u8fc7\u6ee4\u6d41<\/strong><br \/>\n\u8fc7\u6ee4\u6d41\uff08Filter Stream\uff09\u662fJava\u5b57\u8282\u6d41\u7684\u4e00\u79cd\u53d8\u4f53\uff0c\u5b83\u4eec\u53ef\u4ee5\u7528\u4e8e\u5bf9\u5e95\u5c42\u5b57\u8282\u6d41\u8fdb\u884c\u5305\u88c5\uff0c\u6dfb\u52a0\u989d\u5916\u7684\u529f\u80fd\u3002\u4e00\u4e2a\u5e38\u89c1\u7684\u7528\u4f8b\u662f\u4f7f\u7528 BufferedInputStream \u548c BufferedOutputStream \u6765\u63d0\u9ad8\u6027\u80fd\uff0c\u4f46\u8fd8\u6709\u5176\u4ed6\u8fc7\u6ee4\u6d41\u53ef\u4f9b\u9009\u62e9\u3002<\/p>\n<p>\u4f8b\u5982\uff0cDataInputStream \u548c DataOutputStream \u5141\u8bb8\u4f60\u8bfb\u5199\u57fa\u672c\u6570\u636e\u7c7b\u578b\uff0c\u800c\u4e0d\u5fc5\u624b\u52a8\u8fdb\u884c\u5b57\u8282\u64cd\u4f5c\u3002<\/p>\n<pre><code class=\"prettyprint\"  class=\"language-java\">try (DataInputStream dataInputStream = new DataInputStream(new FileInputStream(&quot;data.bin&quot;));\n     DataOutputStream dataOutputStream = new DataOutputStream(new FileOutputStream(&quot;output.bin&quot;))) {\n\n    int number = dataInputStream.readInt();\n    dataOutputStream.writeInt(number * 2);\n    System.out.println(&quot;\u6570\u636e\u5df2\u5904\u7406\u5e76\u5199\u5165 output.bin&quot;);\n} catch (IOException e) {\n    e.printStackTrace();\n}<\/code><\/pre>\n<p><strong>3. \u5e8f\u5217\u5316\u4e0e\u53cd\u5e8f\u5217\u5316<\/strong><\/p>\n<p>Java\u63d0\u4f9b\u4e86\u5bf9\u8c61\u7684\u5e8f\u5217\u5316\u548c\u53cd\u5e8f\u5217\u5316\u529f\u80fd\uff0c\u53ef\u4ee5\u5c06\u5bf9\u8c61\u8f6c\u6362\u4e3a\u5b57\u8282\u6d41\u4ee5\u8fdb\u884c\u5b58\u50a8\u6216\u4f20\u8f93\uff0c\u7136\u540e\u518d\u5c06\u5176\u8fd8\u539f\u4e3a\u5bf9\u8c61\u3002\u8fd9\u5728\u7f51\u7edc\u901a\u4fe1\u548c\u6301\u4e45\u5316\u5b58\u50a8\u4e2d\u975e\u5e38\u6709\u7528\u3002<\/p>\n<pre><code class=\"prettyprint\"  class=\"language-java\">import java.io.*;\n\nclass Person implements Serializable {\n    private String name;\n    private int age;\n\n    public Person(String name, int age) {\n        this.name = name;\n        this.age = age;\n    }\n\n    @Override\n    public String toString() {\n        return &quot;Person{&quot; +\n                &quot;name=&#039;&quot; + name + &#039;\\&#039;&#039; +\n                &quot;, age=&quot; + age +\n                &#039;}&#039;;\n    }\n}\n\npublic class SerializationExample {\n    public static void main(String[] args) {\n        \/\/ \u5e8f\u5217\u5316\u5bf9\u8c61\n        try (ObjectOutputStream outputStream = new ObjectOutputStream(new FileOutputStream(&quot;person.ser&quot;))) {\n            Person person = new Person(&quot;Alice&quot;, 30);\n            outputStream.writeObject(person);\n            System.out.println(&quot;\u5bf9\u8c61\u5df2\u5e8f\u5217\u5316\u5e76\u4fdd\u5b58\u5230 person.ser&quot;);\n        } catch (IOException e) {\n            e.printStackTrace();\n        }\n\n        \/\/ \u53cd\u5e8f\u5217\u5316\u5bf9\u8c61\n        try (ObjectInputStream inputStream = new ObjectInputStream(new FileInputStream(&quot;person.ser&quot;))) {\n            Person person = (Person) inputStream.readObject();\n            System.out.println(&quot;\u4ece person.ser \u53cd\u5e8f\u5217\u5316\u5f97\u5230\u5bf9\u8c61\uff1a&quot; + person);\n        } catch (IOException | ClassNotFoundException e) {\n            e.printStackTrace();\n        }\n    }\n}<\/code><\/pre>\n<p>\u5728\u4e0a\u8ff0\u793a\u4f8b\u4e2d\uff0c\u6211\u4eec\u9996\u5148\u5c06\u4e00\u4e2a Person \u5bf9\u8c61\u5e8f\u5217\u5316\u5e76\u4fdd\u5b58\u5230\u6587\u4ef6 \u201cperson.ser\u201d \u4e2d\uff0c\u7136\u540e\u4ece\u8be5\u6587\u4ef6\u4e2d\u53cd\u5e8f\u5217\u5316\u5bf9\u8c61\u3002\u8fd9\u4f7f\u5f97\u6211\u4eec\u80fd\u591f\u6709\u6548\u5730\u4fdd\u5b58\u548c\u8fd8\u539f\u5bf9\u8c61\u3002<\/p>\n<p><strong>4.\u538b\u7f29\u4e0e\u89e3\u538b\u7f29<\/strong><br \/>\n\u4f7f\u7528Java\u5b57\u8282\u6d41\uff0c\u4f60\u53ef\u4ee5\u8f7b\u677e\u5730\u5c06\u6570\u636e\u538b\u7f29\u4e3aZIP\u6216GZIP\u683c\u5f0f\uff0c\u6216\u8005\u4ece\u538b\u7f29\u6587\u4ef6\u4e2d\u89e3\u538b\u6570\u636e\u3002Java\u63d0\u4f9b\u4e86 ZipInputStream\u3001ZipOutputStream\u3001GZIPInputStream \u548c GZIPOutputStream \u7b49\u7c7b\u6765\u652f\u6301\u8fd9\u4e9b\u64cd\u4f5c\u3002<\/p>\n<pre><code class=\"prettyprint\"  class=\"language-java\">import java.io.*;\nimport java.util.zip.*;\n\npublic class CompressionExample {\n    public static void main(String[] args) {\n        \/\/ \u538b\u7f29\u6587\u4ef6\n        try (FileInputStream fileInputStream = new FileInputStream(&quot;source.txt&quot;);\n             FileOutputStream fileOutputStream = new FileOutputStream(&quot;compressed.zip&quot;);\n             ZipOutputStream zipOutputStream = new ZipOutputStream(fileOutputStream)) {\n\n            ZipEntry zipEntry = new ZipEntry(&quot;source.txt&quot;);\n            zipOutputStream.putNextEntry(zipEntry);\n\n            byte[] buffer = new byte[1024];\n            int bytesRead;\n            while ((bytesRead = fileInputStream.read(buffer)) != -1) {\n                zipOutputStream.write(buffer, 0, bytesRead);\n            }\n\n            zipOutputStream.closeEntry();\n            System.out.println(&quot;\u6587\u4ef6\u5df2\u538b\u7f29\u4e3a compressed.zip&quot;);\n        } catch (IOException e) {\n            e.printStackTrace();\n        }\n\n        \/\/ \u89e3\u538b\u6587\u4ef6\n        try (FileInputStream fileInputStream = new FileInputStream(&quot;compressed.zip&quot;);\n             ZipInputStream zipInputStream = new ZipInputStream(fileInputStream)) {\n\n            ZipEntry zipEntry = zipInputStream.getNextEntry();\n            while (zipEntry != null) {\n                FileOutputStream fileOutputStream = new FileOutputStream(zipEntry.getName());\n                byte[] buffer = new byte[1024];\n                int bytesRead;\n                while ((bytesRead = zipInputStream.read(buffer)) != -1) {\n                    fileOutputStream.write(buffer, 0, bytesRead);\n                }\n                fileOutputStream.close();\n                zipEntry = zipInputStream.getNextEntry();\n            }\n            System.out.println(&quot;compressed.zip \u5df2\u89e3\u538b&quot;);\n        } catch (IOException e) {\n            e.printStackTrace();\n        }\n    }\n}<\/code><\/pre>\n<p><strong>5. \u7f51\u7edc\u7f16\u7a0b<\/strong><\/p>\n<p>Java\u5b57\u8282\u6d41\u4e5f\u5e7f\u6cdb\u7528\u4e8e\u7f51\u7edc\u7f16\u7a0b\uff0c\u7528\u4e8e\u4e0e\u8fdc\u7a0b\u670d\u52a1\u5668\u901a\u4fe1\u3002\u4f60\u53ef\u4ee5\u4f7f\u7528 <code class=\"prettyprint\" >Socket<\/code> \u548c <code class=\"prettyprint\" >ServerSocket<\/code> \u7c7b\u6765\u521b\u5efa\u7f51\u7edc\u5957\u63a5\u5b57\uff0c\u5e76\u4f7f\u7528\u5b57\u8282\u6d41\u5728\u7f51\u7edc\u4e0a\u4f20\u8f93\u6570\u636e\u3002<\/p>\n<p><strong>6. \u5927\u6570\u636e\u5904\u7406<\/strong><\/p>\n<p>\u5728\u5904\u7406\u5927\u6570\u636e\u6587\u4ef6\u65f6\uff0c\u9700\u8981\u5c0f\u5fc3\u5185\u5b58\u7684\u4f7f\u7528\u3002Java\u5b57\u8282\u6d41\u5141\u8bb8\u4f60\u9010\u884c\u6216\u9010\u5757\u5904\u7406\u6570\u636e\uff0c\u800c\u4e0d\u5fc5\u5c06\u6574\u4e2a\u6587\u4ef6\u52a0\u8f7d\u5230\u5185\u5b58\u4e2d\u3002\u8fd9\u5bf9\u4e8e\u5904\u7406\u5927\u578b\u65e5\u5fd7\u6587\u4ef6\u3001\u6570\u636e\u5e93\u5bfc\u51fa\u6587\u4ef6\u7b49\u975e\u5e38\u6709\u7528\u3002<\/p>\n<p>\u6211\u4eec\u8be6\u7ec6\u4ecb\u7ecd\u4e86Java\u5b57\u8282\u6d41\u7684\u57fa\u7840\u77e5\u8bc6\u548c\u5e94\u7528\u3002\u6211\u4eec\u8ba8\u8bba\u4e86\u8f93\u5165\u5b57\u8282\u6d41\u548c\u8f93\u51fa\u5b57\u8282\u6d41\u7684\u5404\u79cd\u7c7b\u522b\uff0c\u5305\u62ec<code class=\"prettyprint\" >FileInputStream<\/code>\u3001<code class=\"prettyprint\" >BufferedInputStream<\/code>\u3001<code class=\"prettyprint\" >DataInputStream<\/code>\u3001<code class=\"prettyprint\" >FileOutputStream<\/code>\u3001<code class=\"prettyprint\" >BufferedOutputStream<\/code>\u548c<code class=\"prettyprint\" >DataOutputStream<\/code>\u3002\u8fd9\u4e9b\u7c7b\u662fJava\u6587\u4ef6\u548c\u6570\u636e\u5904\u7406\u7684\u91cd\u8981\u7ec4\u6210\u90e8\u5206\uff0c\u4e3a\u4f60\u63d0\u4f9b\u4e86\u5f3a\u5927\u7684\u5de5\u5177\u6765\u5904\u7406\u4e8c\u8fdb\u5236\u6570\u636e\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>JAVA \u5b57\u8282\u6d41 \u4ec0\u4e48\u662f\u5b57\u8282\u6d41\uff1f \u5b57\u8282\u6d41\u662fJava\u4e2d\u7528\u4e8e\u5904\u7406\u4e8c\u8fdb\u5236\u6570\u636e\u7684\u4e00\u79cd\u673a\u5236\u3002\u5b83\u4eec\u4e3b\u8981\u7528\u4e8e\u8bfb\u53d6\u548c\u5199\u5165\u5b57\u8282\uff08 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":261,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7,5],"tags":[],"_links":{"self":[{"href":"http:\/\/ericw.top\/index.php?rest_route=\/wp\/v2\/posts\/260"}],"collection":[{"href":"http:\/\/ericw.top\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/ericw.top\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/ericw.top\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/ericw.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=260"}],"version-history":[{"count":1,"href":"http:\/\/ericw.top\/index.php?rest_route=\/wp\/v2\/posts\/260\/revisions"}],"predecessor-version":[{"id":262,"href":"http:\/\/ericw.top\/index.php?rest_route=\/wp\/v2\/posts\/260\/revisions\/262"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/ericw.top\/index.php?rest_route=\/wp\/v2\/media\/261"}],"wp:attachment":[{"href":"http:\/\/ericw.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=260"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/ericw.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=260"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/ericw.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=260"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}