{"id":945,"date":"2017-03-16T15:40:32","date_gmt":"2017-03-16T07:40:32","guid":{"rendered":"http:\/\/www.yusian.com\/blog\/?p=945"},"modified":"2017-03-16T15:42:16","modified_gmt":"2017-03-16T07:42:16","slug":"java%e5%9f%ba%e7%a1%80%e7%9f%a5%e8%af%86%e4%b9%8bio%e6%b5%81%e7%9a%84%e7%ae%80%e5%8d%95%e4%bd%bf%e7%94%a8","status":"publish","type":"post","link":"https:\/\/www.yusian.com\/blog\/java\/2017\/03\/16\/154032945.html","title":{"rendered":"Java\u57fa\u7840\u77e5\u8bc6\u4e4bIO\u6d41\u7684\u7b80\u5355\u4f7f\u7528"},"content":{"rendered":"<pre line=\"1\" lang=\"java\">import java.io.*;\nclass Demo{\n\tpublic static void main(String args[]){\n\t\t\/\/ \u58f0\u660e\u8f93\u5165\u6d41\u7684\u5f15\u7528\n\t\tFileInputStream input = null;\n\t\t\/\/ \u58f0\u660e\u8f93\u51fa\u6d41\u7684\u5f15\u7528\n\t\tFileOutputStream output = null;\n\t\ttry{\n\t\t\t\/\/ \u521d\u59cb\u5316\u4e24\u4e2aio\u5bf9\u8c61\n\t\t\tinput = new FileInputStream(\"\/Users\/yusian\/Documents\/Java\/from.txt\");\n\t\t\toutput = new FileOutputStream(\"\/Users\/yusian\/Documents\/Java\/to.txt\");\n\t\t\t\/\/ \u8bfb\n\t\t\t\/\/ \u63a5\u6536\u8bfb\u53d6\u51fa\u6765\u7684\u5b57\u8282\u6d41\n\t\t\tbyte[] buffer = new byte[100];\n\t\t\t\/\/ \u8bfb\u53d6(\u63a5\u6536\u4f53, \u8d77\u59cb\u4f4d\u7f6e, \u957f\u5ea6)\n\t\t\tinput.read(buffer, 0, buffer.length);\n\t\t\t\/\/ \u5c06\u6570\u7ec4\u5185\u5bb9\u521d\u59cb\u5316\u5230\u5b57\u7b26\u4e32\u4e2d\n\t\t\tString s = new String(buffer);\n\t\t\t\/\/ \u53bb\u9664\u9996\u5c3e\u7a7a\u683c\n\t\t\ts.trim();\n\t\t\t\/\/ \u6253\u5370\u5b57\u7b26\u4e32\n\t\t\tSystem.out.println(s);\n\t\t\t\n\t\t\t\/\/ \u5199\n\t\t\t\/\/ \u5c06\u6570\u7ec4\u4e2d\u7684\u5185\u5bb9\u5199\u5165\u5230\u6587\u4ef6\u4e2d\n\t\t\toutput.write(buffer, 0, buffer.length);\n\t\t}catch(Exception e){\n\t\t\tSystem.out.println(e);\n\t\t}\n\t}\n}<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>import java.io.*; class Demo{ public static void main(String args[]){ \/\/ \u58f0\u660e\u8f93\u5165\u6d41\u7684\u5f15\u7528 FileInputStream input = null; \/\/ \u58f0\u660e\u8f93\u51fa\u6d41\u7684\u5f15\u7528 FileOutputStream output = null; try{ \/\/ \u521d\u59cb\u5316\u4e24\u4e2aio\u5bf9\u8c61 input = new FileInputStream(&#8220;\/Users\/yusian\/Documents\/Java\/from.txt&#8221;); output = new FileOutputStream(&#8220;\/Users\/yusian\/Documents\/Java\/to.txt&#8221;); \/\/ \u8bfb \/\/ \u63a5\u6536\u8bfb\u53d6\u51fa\u6765\u7684\u5b57\u8282\u6d41 byte[] buffer = new byte[100]; \/\/ \u8bfb\u53d6(\u63a5\u6536\u4f53, \u8d77\u59cb\u4f4d\u7f6e, \u957f\u5ea6) input.read(buffer, 0, buffer.length); \/\/ \u5c06\u6570\u7ec4\u5185\u5bb9\u521d\u59cb\u5316\u5230\u5b57\u7b26\u4e32\u4e2d String s = new String(buffer); [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[35],"tags":[34,20],"class_list":["post-945","post","type-post","status-publish","format-standard","hentry","category-java","tag-java","tag-basics"],"_links":{"self":[{"href":"https:\/\/www.yusian.com\/blog\/wp-json\/wp\/v2\/posts\/945","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.yusian.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.yusian.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.yusian.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.yusian.com\/blog\/wp-json\/wp\/v2\/comments?post=945"}],"version-history":[{"count":0,"href":"https:\/\/www.yusian.com\/blog\/wp-json\/wp\/v2\/posts\/945\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.yusian.com\/blog\/wp-json\/wp\/v2\/media?parent=945"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.yusian.com\/blog\/wp-json\/wp\/v2\/categories?post=945"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.yusian.com\/blog\/wp-json\/wp\/v2\/tags?post=945"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}