电脑太渣,好慢。。反正速率是:

高效字节流一次读写一个字节数组  >  基本字节流一次读写一个字节数组  > 高效字节流一次读写一个字节 >  基本字节流一次读写一个字节

  前两个远远快过后面2个
 package zl_IOdemo;

 import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException; /*
* 需求:把D:\music\音乐\Beyond - 不再犹豫.mp3复制到当前项目目录下的copy.mp4中
*
* 字节流四种方式复制文件:
* 基本字节流一次读写一个字节:
* 基本字节流一次读写一个字节数组:
* 高效字节流一次读写一个字节:
* 高效字节流一次读写一个字节数组:
*/
public class CopyMp4 { public static void main(String[] args) throws IOException {
long start = System.currentTimeMillis();
//分别针对四种方式各创建一个方法,
//参数列表:String 数据源 String 目的地
//返回类型 void
method1("D:\\music\\音乐\\Beyond - 不再犹豫.mp3","copy.mp3");
//method2("D:\\music\\音乐\\Beyond - 不再犹豫.mp3","copy.mp3");
//method3("D:\\music\\音乐\\Beyond - 不再犹豫.mp3","copy.mp3");
//method4("D:\\music\\音乐\\Beyond - 不再犹豫.mp3","copy.mp3");
long end = System.currentTimeMillis();
System.out.println(end);
System.out.println("一共耗时"+(end - start)+"毫秒"); } private static void method4(String start , String end) throws IOException {
//高效字节流一次读写一个字节数组
BufferedInputStream in = new BufferedInputStream(new FileInputStream(start));
BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(end));
byte[] by = new byte[1024];
int lend = 0;
while((lend = in.read(by)) != -1){
out.write(by,0,lend);
}
in.close();
out.close(); } private static void method3(String start , String end) throws IOException {
// 高效字节流一次读写一个字节
BufferedInputStream in = new BufferedInputStream(new FileInputStream(start));
BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(end));
int lend = 0;
while(( lend = in.read()) != -1){
out.write(lend);
}
in.close();
out.close();
} private static void method2(String start , String end) throws IOException {
// 基本字节流一次读写一个字节数组
FileInputStream in = new FileInputStream(start);
FileOutputStream out = new FileOutputStream(end); byte[] by = new byte[1024];
int lend = 0;
while((lend = in.read(by)) != -1){
out.write(by,0,lend);
}
in.close();
out.close(); } private static void method1(String start , String end) throws IOException {
// 基本字节流一次读写一个字节
//创建基本字节输入流,以便从数据源读取文件
FileInputStream in = new FileInputStream(start);
//创建基本字节输出流,以便写入数据到目的地
FileOutputStream out = new FileOutputStream(end);
//复制目标文件
int i = 0;
while((i = in.read()) != -1){
out.write(i);
}
in.close();
out.close(); } }

最新文章

  1. (原创)解决.net 下使用uploadify,在火狐浏览器下的error 302
  2. leetcode 186. Reverse Words in a String II 旋转字符数组 ---------- java
  3. C# 线程同步
  4. Vector3.Lerp 插值
  5. DSP5509的时钟发生器(翻译总结自TI官方文档)
  6. css 控制滚动样式
  7. bzoj 1303: [CQOI2009]中位数图
  8. Light OJ Dynamic Programming
  9. VS Code C# 插件离线版 1.6.2
  10. ORACLE跨数据库查询的方法
  11. Codeforces 830C Bamboo Partition (看题解)
  12. HTML 第十二章总结
  13. Explain之key_len长度计算
  14. November 20th 2016 Week 47th Sunday
  15. 记一次centos6升级salt-minion启动失败的问题
  16. 【css】CSS3 Media Queries 详解【转】
  17. 安装并开启ssh服务
  18. caffe-安装anaconda后重新编译caffe报错
  19. 基于Requests和BeautifulSoup实现“自动登录”
  20. NO.3 Android SDK 高效更新

热门文章

  1. [性能] Bean拷贝工具类性能比较
  2. jquery只能输入数字方法
  3. MongoDB整合Spring
  4. Web打印控件
  5. JTS Geometry关系判断和分析
  6. Enforcing the correct protocol for partially SSL secured SharePoint sites
  7. GridView总结二:GridView自带编辑删除更新
  8. Android屏蔽HOME键
  9. EdgesForExtendedLayout
  10. SQL语句的简单使用