public class CopyMp4Demo {
public static void main(String[] args) throws IOException {
long start = System.currentTimeMillis();
// method1("e:\\test.mp4", "copy4.mp4");
// method2("e:\\test.mp4", "copy4.mp4");
// method3("e:\\test.mp4", "copy4.mp4");
method4("e:\\test.mp4", "copy4.mp4");
long end = System.currentTimeMillis();
System.out.println("共耗时:" + (end - start) + "毫秒");
} // 高效字节流一次读写一个字节数组:
public static void method4(String srcString, String destString)
throws IOException {
BufferedInputStream bis = new BufferedInputStream(new FileInputStream(
srcString));
BufferedOutputStream bos = new BufferedOutputStream(
new FileOutputStream(destString)); byte[] bys = new byte[1024];
int len = 0;
while ((len = bis.read(bys)) != -1) {
bos.write(bys, 0, len);
} bos.close();
bis.close();
} // 高效字节流一次读写一个字节:
public static void method3(String srcString, String destString)
throws IOException {
BufferedInputStream bis = new BufferedInputStream(new FileInputStream(
srcString));
BufferedOutputStream bos = new BufferedOutputStream(
new FileOutputStream(destString)); int by = 0;
while ((by = bis.read()) != -1) {
bos.write(by); } bos.close();
bis.close();
} // 基本字节流一次读写一个字节数组
public static void method2(String srcString, String destString)
throws IOException {
FileInputStream fis = new FileInputStream(srcString);
FileOutputStream fos = new FileOutputStream(destString); byte[] bys = new byte[1024];
int len = 0;
while ((len = fis.read(bys)) != -1) {
fos.write(bys, 0, len);
} fos.close();
fis.close();
} // 基本字节流一次读写一个字节
public static void method1(String srcString, String destString)
throws IOException {
FileInputStream fis = new FileInputStream(srcString);
FileOutputStream fos = new FileOutputStream(destString); int by = 0;
while ((by = fis.read()) != -1) {
fos.write(by);
} fos.close();
fis.close();
}
}

字节流四种方式复制文件:
基本字节流一次读写一个字节: 共耗时:117235毫秒
 基本字节流一次读写一个字节数组: 共耗时:156毫秒
 高效字节流一次读写一个字节: 共耗时:1141毫秒
 高效字节流一次读写一个字节数组: 共耗时:47毫秒

推荐使用第四种,即 高效字节流一次读写一个字节数组 方式读取文件。

IO之4种字节流拷贝文件方式对比的更多相关文章

  1. Selenium系列(十一) - 针对两种上传文件方式的实现方案

    如果你还想从头学起Selenium,可以看看这个系列的文章哦! https://www.cnblogs.com/poloyy/category/1680176.html 其次,如果你不懂前端基础知识, ...

  2. 使用Java字节流拷贝文件

    本文给出使用Java字节流实现文件拷贝的例子 package LearnJava; import java.io.*; public class FileTest { public static vo ...

  3. hadoop中两种上传文件方式

    记录如何将本地文件上传至HDFS中 前提是已经启动了hadoop成功(nodedate都成功启动) ①先切换到HDFS用户 ②创建一个user件夹 bin/hdfs dfs -mkdir /user ...

  4. [JAVA]使用字节流拷贝文件

    import java.io.*; /** * @Description: * @projectName:JavaTest * @see:PACKAGE_NAME * @author:郑晓龙 * @c ...

  5. [JAVA]字节流拷贝文件

    import java.io.*; public class CopyFile { public static void main(String[] args) { //1.创建源 File in = ...

  6. js/css在html文档中的引用外部文件方式对比

    包含css样式表和js脚本的最好方式是使用外部文件,因为css/js和html标记文档可以清晰地分离. css的外部引用写在<head></head>中: <head&g ...

  7. mui几种页面跳转方式对比

    1.初始化时创建子页面 mui.init({ subpages: [{ url: your - subpage - url, //子页面HTML地址,支持本地地址和网络地址 id: your - su ...

  8. java IO之 File类+字节流 (输入输出 缓冲流 异常处理)

    1. File类

  9. java——io、字节流缓冲区拷贝文件、字节缓冲流

    使用try catch finally关闭文件流: 写入文件: import java.io.*; public class exp{ public static void main(String[] ...

随机推荐

  1. Jmeter学习(三十二)调试工具Debug Sampler(转载)

    转载自 http://www.cnblogs.com/yangxia-test 一.Debug Sampler介绍: 使用Jmeter开发脚本时,难免需要调试,这时可以使用Jmeter的Debug S ...

  2. java定义object数组(可以存储String或int等多种类型)

    需求| 想在数组中既有String类型又有int等类型,所以需要定义数组为Object类型   背景| 现在有一个字符串params,需要对其进行逗号分隔赋值到数组里,这时遇到了个问题,即使直接定义的 ...

  3. jquery获取焦点位于的元素

    参考 https://zhidao.baidu.com/question/497311181016643684.html if ($(":focus").length > 0 ...

  4. PHP采集利器:Snoopy 试用心得

    Snoopy.class.php下载 Snoopy是一个php类,用来模拟浏览器的功能,可以获取网页内容,发送表单.Snoopy正确运行需要你的服务器的PHP版本在4以上,并且支持PCRE(Perl ...

  5. 用photoshop 把视频镜头做成GIF图片

    https://jingyan.baidu.com/article/47a29f2432e113c0142399b0.html

  6. PAT1020 (已知中序,后序遍历转前序遍历)

    已知后序与中序输出前序(先序):后序:3, 4, 2, 6, 5, 1(左右根)中序:3, 2, 4, 1, 6, 5(左根右) 已知一棵二叉树,输出前,中,后时我们采用递归的方式.同样也应该利用递归 ...

  7. 33. Search in Rotated Sorted Array (Array;Divide-and-Conquer)

    Suppose a sorted array is rotated at some pivot unknown to you beforehand. (i.e., 0 1 2 4 5 6 7 migh ...

  8. 游戏行业的女性拥有强大的新盟友:Facebook

    据外媒 TheNextWeb 报道,Facebook 本周宣布其新的游戏行业女性倡议,致力于鼓励更多的女性加入游戏行业.这家社交媒体公司专注于提供榜样和成功故事,而这实际上是一种令人愉快的方式.虽然游 ...

  9. sourceforge

    sourceforge SourceForge.net,又称SF.net,是开源软件开发者进行开发管理的集中式场所. SourceForge.net由VA Software提供主机,并运行Source ...

  10. day 16 包,random,shutil

    包: 函数过多,可以分模块文件去管理函数,模块文件过多,将模块文件分类放在一个个的文件夹中,这个文件夹就叫做包,组织结构更加清晰,合理! 模式就是被别人使用,包既然是一些模块的集合,也是被调用. 文件 ...