使用字符缓冲区相关实现copy文件;

public static void main(String[] args) {
//创建文件对象指定要拷贝的文件路径(源文件),文件须存在,测试用例不做判断
File srcFile=new File("E:\\CloudMusic\\mp3\\a.mp3");
//创建文件对象指定文件拷贝的目标路径
File destFile=new File("d:\\test1.mp3");
System.out.println("正在复制文件.......");
try {
//创建文件输入流对象
FileInputStream fin=new FileInputStream(srcFile);
//创建缓冲区输入流对象(加快文件的读取效率)
BufferedInputStream bin=new BufferedInputStream(fin); //创建文件输出流对象
FileOutputStream fout=new FileOutputStream(destFile);
//创建缓冲区输出流对象,加快文件流的输出效率
BufferedOutputStream bout=new BufferedOutputStream(fout); //声明int类型的变量准备逐字节拷贝文件
int b;
while((b=bin.read())!=-){
bout.write(b);//写出字节到文件
} bout.flush();
bout.close();
bin.close();
System.out.println("文件拷贝结束!");
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}

最新文章

  1. 设置JDK环境变量(linux版)
  2. spark编写word count
  3. 用centos光盘安装RPM包的方法
  4. cocos2dx 安卓编译问题收集
  5. python 中 sorted() 和 list.sort() 的用法
  6. Windows 7 32位上硬盘安装linux[ubuntu13.04] 双系统
  7. HttpClient设置代理,超时,以及得到cookies
  8. Oracle 监听配置详解(转载)
  9. python高级编程之超类02:super的缺陷
  10. 基于visual Studio2013解决面试题之0905子串数量
  11. 微信iOS收款到账语音提醒开发总结
  12. PDA(Windows Mobile)调用远程WebService
  13. windows使用im4java 提示FileNotFoundException
  14. LeetCode-63. 不同路径 II
  15. reduce方法简单实现数组中对象去重
  16. GPUImage中饱和度调整的实现——GPUImageSaturationFilter
  17. Google Kickstart Round.B C. Diverse Subarray
  18. java的redis工具类
  19. 《剑指offer》第十九题(正则表达式匹配)
  20. vsftp 500 OOPS: cannot change directory:/home/xyp

热门文章

  1. TensorFlow验证码识别
  2. 剑指Offer - 九度1351 - 数组中只出现一次的数字
  3. 《Cracking the Coding Interview》——第13章:C和C++——题目4
  4. 《Cracking the Coding Interview》——第2章:链表——题目6
  5. script async和defer
  6. serial console
  7. Python——开篇之词
  8. Struts2+DAO层实现实例03——添加监听器跟踪用户行为
  9. Android自定义控件 -Canvas绘制折线图(实现动态报表效果)
  10. poj 2151 概率DP(水)