IO之4种字节流拷贝文件方式对比
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种字节流拷贝文件方式对比的更多相关文章
- Selenium系列(十一) - 针对两种上传文件方式的实现方案
如果你还想从头学起Selenium,可以看看这个系列的文章哦! https://www.cnblogs.com/poloyy/category/1680176.html 其次,如果你不懂前端基础知识, ...
- 使用Java字节流拷贝文件
本文给出使用Java字节流实现文件拷贝的例子 package LearnJava; import java.io.*; public class FileTest { public static vo ...
- hadoop中两种上传文件方式
记录如何将本地文件上传至HDFS中 前提是已经启动了hadoop成功(nodedate都成功启动) ①先切换到HDFS用户 ②创建一个user件夹 bin/hdfs dfs -mkdir /user ...
- [JAVA]使用字节流拷贝文件
import java.io.*; /** * @Description: * @projectName:JavaTest * @see:PACKAGE_NAME * @author:郑晓龙 * @c ...
- [JAVA]字节流拷贝文件
import java.io.*; public class CopyFile { public static void main(String[] args) { //1.创建源 File in = ...
- js/css在html文档中的引用外部文件方式对比
包含css样式表和js脚本的最好方式是使用外部文件,因为css/js和html标记文档可以清晰地分离. css的外部引用写在<head></head>中: <head&g ...
- mui几种页面跳转方式对比
1.初始化时创建子页面 mui.init({ subpages: [{ url: your - subpage - url, //子页面HTML地址,支持本地地址和网络地址 id: your - su ...
- java IO之 File类+字节流 (输入输出 缓冲流 异常处理)
1. File类
- java——io、字节流缓冲区拷贝文件、字节缓冲流
使用try catch finally关闭文件流: 写入文件: import java.io.*; public class exp{ public static void main(String[] ...
随机推荐
- fiddler对浏览器、app抓包及证书安装(转)
http://blog.csdn.net/u011608531/article/details/50838227 1.fiddler对浏览器抓包 1.1 对浏览器的http的抓包 Capturing开 ...
- MyLineNumberReader
package com.itheima; import java.io.FileReader; import java.io.IOException; import java.io.Reader; p ...
- YARN 的深入简出
1.YARN的产生背景 2.YARN的执行流程 3.YARN的概述 4.YARN的环境搭建 5.YARN的架构 6.如何提交作业到YaRN上执行 YARN的产生MapReduce1.x存在多种问题单节 ...
- C++求图任意两点间的所有路径
基于连通图,邻接矩阵实现的图,非递归实现. 算法思想: 设置两个标志位,①该顶点是否入栈,②与该顶点相邻的顶点是否已经访问. A 将始点标志位①置1,将其入栈 B 查看栈顶节点V在图中,有没有可以到达 ...
- laravel中的模型关联之(一对多)
一对多 一对多就相当于,一个用户有多篇文章,这多篇文章都对应一个用户 这是一张文章表,一个用户有多篇文章,这里是在用户模型里面获取用户的所有文章, 第二个参数就是获取的模型文章表(post)里面的用户 ...
- EOJ Monthly 2018.7 B.锐角三角形(数学几何+思维)
描述 是否存在面积为S/2的整点锐角三角形?存在输出Yes并输出三个整点坐标,否则输出No. 注意如果存在输出的坐标必须在long long范围内. Input 第一行一个整数S(1<=S< ...
- 常用的key和oid
1.FortiGate Template-Network-Office-Fortigate-Session Count:key,fgSysSesCount oid,.1.3.6.1.4.1.123 ...
- 使用python读写CSV文件
# -*- coding:UTF-8 -*- __autor__ = 'zhouli' __date__ = '2018/10/25 21:14' import csv with open('resu ...
- [leetcode]304. Range Sum Query 2D - Immutable二维区间求和 - 不变
Given a 2D matrix matrix, find the sum of the elements inside the rectangle defined by its upper lef ...
- Struts2框架的数据封装一之属性封装(属性封装的第二种方式:封装成javaBean)
Struts2中提供了两类数据封装的方式? 第一种方式:属性驱动(有两种方式:一个对属性,另外一个是将参数封装到javaBean中) B. 在页面上,使用OGNL表达式进行数据封装.(将参数封装到ja ...