首页 > 代码库 > 字符输入输出流
字符输入输出流
package com.sxt.copy2; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; import java.io.Reader; import java.io.Writer; /* * 字符输入输出流 * Reader * Writer */ public class TestCopy { public static void main(String[] args) { Reader reader = null; Writer writer = null; try { reader = new FileReader("F:\\01_面向对象设计思想_重要_1.avi"); writer = new FileWriter("G:\\CopyDest.avi"); char[] cbuf = new char[1024]; //第一步:读文件到程序 int len = 0; while((len = reader.read(cbuf))!= -1){ System.out.println(len); writer.write(cbuf, 0, len);//第二部:从程序写到文件中 } System.out.println("Copy执行完成!"); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); }finally{ if(reader != null){ try { reader.close(); } catch (IOException e) { e.printStackTrace(); } } if(writer != null){ try { writer.close(); } catch (IOException e) { e.printStackTrace(); } } } } }
字符输入输出流
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。