参考手册:


BufferedInputStream


BufferedOutputStream



实例:

import java.io.*;
/*
* 文件的复制方式
* 1 字节流读写单个字节
* 2 字节流读写字节数组
* 3 字节流缓冲区 读写单个字节
* 4 字节流缓冲区读写字节数组
*/
public class Zjsrsclx {
public static void main(String[] args) throws Exception {
long e = System.currentTimeMillis();
File src = new File("D:\\ja.txt");
File dasc = new File("C:\\ja.txt");
long c = System.currentTimeMillis();
System.out.println(e-c);
lx4(src,dasc);
} private static void lx4(File src, File dasc) throws Exception {
// 4 字节流缓冲区读写字节数组
BufferedInputStream bis = new BufferedInputStream(new FileInputStream(src));
BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(dasc));
byte[] b = new byte[1024*10];
int len = 0;
while((len = bis.read(b))!=-1){
bos.write(b,0,len);
}
bis.close();
bos.close();
} private static void lx3(File src, File dasc) throws Exception {
//3 字节流缓冲区 读写单个字节
BufferedInputStream bis = new BufferedInputStream(new FileInputStream(src));
BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(dasc));
int len = 0;
while((len = bis.read())!=-1){
bos.write(len);
}
bis.close();
bos.close();
} private static void lx2(File src, File dasc) throws Exception {
//2 字节流读写字节数组
FileInputStream fis = new FileInputStream(src);
FileOutputStream fos = new FileOutputStream(dasc);
int len = 0;
byte[] b = new byte[1024*10];
while ((len = fis.read(b))!=-1){
fos.write(b,0,len);
}
fis.close();
fos.close();
} private static void lx1(File src,File dasc) throws Exception {
//1 字节流读写单个字节
//复制粘贴文件。
FileInputStream fis = new FileInputStream(src);
FileOutputStream fos = new FileOutputStream(dasc); int len = 0;
while ((len = fis.read())!=-1){
fos.write(len);
}
fis.close();
fos.close();
} }

 


打印结果:


lx1:


lx2:


lx3:


lx4:

最新文章

  1. UDP异步通信
  2. 一些常用的Bootstrap模板资源站
  3. pip 豆瓣镜像使用
  4. maven编译项目理解
  5. c#经典俄罗斯方块 vs2012开发
  6. .net iis 域名泛解析实战
  7. Best MVC Practices(最优的MVC布局)
  8. 【转】qlv文件如何转换成mp4 怎样把下载好的qlv格式视频转换成MP4格式
  9. Welcome to Django!
  10. ffdshow 源代码分析 9: 编解码器有关类的总结
  11. SQL SERVER 执行动态SQL EXEC
  12. docker学习系列(二):使用Dockerfile创建自己的镜像
  13. winreg模块的使用
  14. 151. Reverse Words in a String(java 注意细节处理)
  15. SRM471
  16. poj1703 Find them, Catch them(带权并查集)
  17. poj1673 EXOCENTER OF A TRIANGLE
  18. linux设备驱动模型-浅析-转
  19. Computer Generated Angular Fisheye Projections [转]
  20. Entity Framework 中 Schema是什么

热门文章

  1. FOR xml path 这么爽的SQL命令,居然今天才知道
  2. 推荐几位jenkins发布war包和jar包大佬的博客
  3. 网站log记录
  4. js中判断为false的情况
  5. rest-framework源码解析和自定义组件----版本
  6. OpenGL Panorama Player
  7. C++扬帆远航——6(三色球)
  8. C++与引用2
  9. GitLab-CI部署及踩坑总结
  10. go微服务框架kratos学习笔记十(熔断器)