{"id":669,"date":"2019-02-22T23:05:53","date_gmt":"2019-02-22T15:05:53","guid":{"rendered":"http:\/\/www.eait.co\/?p=669"},"modified":"2019-04-05T12:30:43","modified_gmt":"2019-04-05T04:30:43","slug":"java-%e4%bd%bf%e7%94%a8%e5%ad%97%e7%ac%a6%e4%b8%b2%e8%af%bb%e5%8f%96%e8%be%93%e5%87%ba%e5%88%b0txt","status":"publish","type":"post","link":"https:\/\/notes.coremix.net\/?p=669","title":{"rendered":"java\u2014\u2014\u4f7f\u7528\u5b57\u7b26\u4e32\u8bfb\u53d6\u8f93\u51fa\u5230txt"},"content":{"rendered":"<pre>package filetest;\r\nimport java.io.*;\r\npublic class chardemo {\r\n    public static void main(String argsp[])\r\n    {\r\n        File f = new File(\"C:\\\\temp2.txt\");\r\n        Writer out = null;\r\n        try{\r\n            out = new FileWriter(f);\r\n        }\r\n        catch(IOException e)\r\n        {\r\n            e.printStackTrace();\r\n        }\r\n        \/\/\u58f0\u660e\u4e00\u4e2astring\u5bf9\u8c61\r\n        String str = \"Hello World!!!\";\r\n        try{\r\n            \/\/\u5c06str\u7684\u5185\u5bb9\u5199\u5165\u5230\u6587\u4ef6\u4e2d\r\n            out.write(str);\r\n        }\r\n        catch (IOException e1){\r\n            e1.printStackTrace();\r\n        }\r\n        try{\r\n            out.close();\r\n        }\r\n        catch (IOException e2){\r\n            e2.printStackTrace();\r\n        }\r\n        \/\/\u4ee5\u4e0b\u4e3a\u8bfb\u6587\u4ef6\u64cd\u4f5c\r\n        Reader in = null;\r\n        try{\r\n            in = new FileReader(f);\r\n        }\r\n        catch(FileNotFoundException e3){\r\n            e3.printStackTrace();\r\n        }\r\n        \/\/\u5f00\u8f9f\u4e00\u4e2a\u7a7a\u95f4\u7528\u4e8e\u63a5\u6536\u6587\u4ef6\u8bfb\u8fdb\u6765\u7684\u6570\u636e\r\n        char c1[] = new char[1024];\r\n        int i = 0;\r\n        try{\r\n            \/\/\u5c06c1\u7684\u5f15\u7528\u4f20\u9012\u5230read\uff08\uff09\u65b9\u6cd5\u4e4b\u4e2d\uff0c\u540c\u65f6\u6b64\r\n            \/\/\u65b9\u6cd5\u8fd4\u56de\u8bfb\u5165\u6570\u636e\u7684\u4e2a\u6570\r\n            i = in.read(c1);\r\n        }\r\n        catch(IOException e4){\r\n            e4.printStackTrace();\r\n        }\r\n        try\r\n        {\r\n            in.close();\r\n        }\r\n        catch(IOException e5){\r\n            e5.printStackTrace();\r\n        }\r\n        \/\/\u5c06\u5b57\u7b26\u6570\u7ec4\u8f6c\u6362\u4e3a\u5b57\u7b26\u4e32\u8f93\u51fa\r\n        System.out.println(new String(c1,0,i));\r\n    }\r\n\r\n}\r\n\r\n\r\n\r\n<span style=\"color: #ff0000;\">\u82e5\u5c0624-28\u884c\u6ce8\u91ca\u6389\uff0c\u4e5f\u5c31\u662f\u6700\u540e\u4e0d\u5173\u95ed\u6587\u4ef6\uff0c\u5c31\u4f1a\u53d1\u73b0\u4e0b\u9762\u8bfb\u53d6\u7684\u7ed3\u679c\u662f\u7a7a\u767d\u3002\u539f\u56e0\u662f\uff1a\r\n\u67e5\u770bJDK\u53ef\u4ee5\u770b\u5230\uff0cFile Writer\u7c7b\u5e76\u4e0d\u662f\u76f4\u63a5\u7ee7\u627f\u81eaWriter\u7c7b\uff0c\u4e8c\u5341\u7ee7\u627f\u4e86Writer\u7684\u5b50\u7c7b\uff08OutputStreamWriter\uff09\uff0c\u6b64\u7c7b\u4e3a\u5b57\u8282\u6d41\u548c\u5b57\u7b26\u6d41\u7684\u8f6c\u6362\u7c7b\uff0c\u4e5f\u5c31\u662f\u8bf4\u771f\u6b63\u4ece\u6587\u4ef6\u8bfb\u53d6\u8fdb\u6765\u7684\u6570\u636e\u8fd8\u662f\u5b57\u8282\uff0c\u53ea\u662f\u5728\u5185\u5b58\u4e2d\u5c06\u5b57\u8282\u8f6c\u6362\u6210\u4e86\u5b57\u7b26\u3002\u6240\u4ee5\u53ef\u5f97\u51fa\u4e00\u4e2a\u7ed3\u8bba\uff1a\u5b57\u7b26\u6d41\u7528\u5230\u4e86\u7f13\u51b2\u533a\uff0c\u4e8c\u5b57\u8282\u6d41\u6ca1\u6709\u7528\u5230\u7f13\u51b2\u533a\uff0c\u53e6\u5916\u4e5f\u53ef\u4ee5\u7528Writer\u7c7b\u4e2dflush\uff08\uff09\u65b9\u6cd5\u5f3a\u5236\u6e05\u7a7a\u7f13\u51b2\u533a\u3002\r\n<\/span><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>package filetest; import java.io.*; public class charde [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[22,24],"tags":[],"class_list":["post-669","post","type-post","status-publish","format-standard","hentry","category-java","category-base_code"],"blocksy_meta":[],"_links":{"self":[{"href":"https:\/\/notes.coremix.net\/index.php?rest_route=\/wp\/v2\/posts\/669","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/notes.coremix.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/notes.coremix.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/notes.coremix.net\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/notes.coremix.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=669"}],"version-history":[{"count":3,"href":"https:\/\/notes.coremix.net\/index.php?rest_route=\/wp\/v2\/posts\/669\/revisions"}],"predecessor-version":[{"id":672,"href":"https:\/\/notes.coremix.net\/index.php?rest_route=\/wp\/v2\/posts\/669\/revisions\/672"}],"wp:attachment":[{"href":"https:\/\/notes.coremix.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=669"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/notes.coremix.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=669"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/notes.coremix.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=669"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}