//package 字符缓冲流bufferreaderDemo;

 import java.io.BufferedOutputStream;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.BufferedInputStream;
import java.io.IOException; /*
* 四种方式实现大文件数据的读取写入--->复制
* 1.基本字节流一次读取一个字节 最慢
* 2.基本字节流一次读取一个字节数组 较快 (优选)
* 3.高效字节流一次读取一个字节 比较快
* 4.高校字节流一次读取一个字节数组 很快 (优选)
*
*/
public class Test2 {
public static void main(String[] args) throws IOException {
long start = System.currentTimeMillis(); // method1("E:\\b.txt", "c.txt");
// method2("E:\\b.txt", "c.txt");
// method3("E:\\b.txt", "c.txt");
method4("E:\\b.txt", "c.txt"); long end = System.currentTimeMillis();
System.out.println("共耗时: " + (end - start) + "毫秒");
} // 1.基本方法字节流一次读取一个字节
public static void method1(String srcPath, String destPath)
throws IOException {
// 读取数据对象
FileInputStream fis = new FileInputStream(srcPath);
// 写入数据目标文件路径
FileOutputStream fos = new FileOutputStream(destPath);
// 数据读写
// 直接以单字节读取
int by = 0;
while ((by = fis.read()) != -1) {
fos.write(by);
}
// 关闭流
fos.close();
fis.close();
} // 2.基本字节读取一次读取一个数组
public static void method2(String srcPath, String destPath)
throws IOException {
// 数据读取的对象封装
FileInputStream fis = new FileInputStream(srcPath);
// 数据写入对象封装
FileOutputStream fos = new FileOutputStream(destPath);
// 数据的读写
byte[] bys = new byte[1024];
int len = 0;
while ((len = fis.read(bys)) != -1) {
fos.write(bys, 0, len);
}
// 关闭流
fis.close();
fos.close();
} // 3.高效字节流一次读取一个字节
public static void method3(String srcPath, String destPath)
throws IOException {
// 数据读取对象封装
BufferedInputStream bis = new BufferedInputStream(new FileInputStream(
srcPath));
// 数据写入对象封装
BufferedOutputStream bos = new BufferedOutputStream(
new FileOutputStream(destPath)); // 数据读写操作
int by = 0;
while ((by = bis.read()) != -1) {
bos.write(by);
} // 关闭流
bos.close();
bis.close();
} // 4.高效字节流读取一个字节数组
public static void method4(String srcPath, String destPath)
throws IOException {
// 数据读取对象封装
BufferedInputStream bis = new BufferedInputStream(new FileInputStream(
srcPath));
// 数据写入对象
BufferedOutputStream bos = new BufferedOutputStream(
new FileOutputStream(destPath)); // 数据读写操作
byte[] bys = new byte[1024];
int len = 0;
while ((len = bis.read(bys)) != -1) {
bos.write(bys, 0, len);
} // 关闭流
bos.close();
bis.close();
}
}

Java使用基本字节流OutputStream的四种方式对于数据复制(文本,音视频,图像等数据)的更多相关文章

  1. 普通java类加入spring容器的四种方式

    今天在自己开发的工具类中使用了spring注入的方式调用了其他类,但是发生的报错,在整理了后今天小结一下. 首先简单介绍下spring容器,spring容器是整个spring框架的核心,通常我们说的s ...

  2. Java中获取系统时间的四种方式

    第一种: Date day=new Date(); SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss" ...

  3. Java实现文件复制的四种方式

    背景:有很多的Java初学者对于文件复制的操作总是搞不懂,下面我将用4中方式实现指定文件的复制. 实现方式一:使用FileInputStream/FileOutputStream字节流进行文件的复制操 ...

  4. Java遍历Map对象的四种方式

    关于java中遍历map具体哪四种方式,请看下文详解吧. 方式一 :这是最常见的并且在大多数情况下也是最可取的遍历方式.在键值都需要时使用. Map<Integer, Integer> m ...

  5. 【转】Java遍历Map对象的四种方式

    关于java中遍历map具体哪四种方式,请看下文详解吧. 方式一 这是最常见的并且在大多数情况下也是最可取的遍历方式.在键值都需要时使用. Map<Integer, Integer> ma ...

  6. js 复制文本的四种方式

    js 复制文本的四种方式 一.总结 一句话总结:js文本复制主流方法:document的execCommand方法 二.js 复制文本的四种方式 纯 转载复制,非原创 原地址:http://www.c ...

  7. java 20 -10 字节流四种方式复制mp3文件,测试效率

    电脑太渣,好慢..反正速率是: 高效字节流一次读写一个字节数组 > 基本字节流一次读写一个字节数组 > 高效字节流一次读写一个字节 > 基本字节流一次读写一个字节 前两个远远快过后面 ...

  8. 【Java EE 学习 80 下】【调用WebService服务的四种方式】【WebService中的注解】

    不考虑第三方框架,如果只使用JDK提供的API,那么可以使用三种方式调用WebService服务:另外还可以使用Ajax调用WebService服务. 预备工作:开启WebService服务,使用jd ...

  9. JAVA中集合输出的四种方式

    在JAVA中Collection输出有四种方式,分别如下: 一) Iterator输出. 该方式适用于Collection的所有子类. public class Hello { public stat ...

随机推荐

  1. Linux权限值问题

    0660:从左向右:第一位:(我不清楚,也没有用过)第二位:当前用户的经权限:6=110(二进制),每一位分别对就 可读,可写,可执行,,6说明当前用户可读可写不可执行第三位:group组用户,6的意 ...

  2. HashMap 扩容 加载因子

    HashMap: public HashMap(int initialCapacity, float loadFactor) { //初始容量不能<0 if (initialCapacity & ...

  3. python 环境问题

    1. 查看python安装的模块及版本 $pip freeze Babel== Flask== Flask-HTTPAuth== Flask-RESTful== Flask-SQLAlchemy==2 ...

  4. REST Security with JWT using Java and Spring Security

    Security Security is the enemy of convenience, and vice versa. This statement is true for any system ...

  5. [Call Vibrator] How to Enable Outgoing Call Vibration without ROOT

    Call Vibrator requires the radio log of phone to detect when outgoing call is answered. But since An ...

  6. 使用Java创建RESTful Web Service

    REST是REpresentational State Transfer的缩写(一般中文翻译为表述性状态转移).2000年Roy Fielding博士在他的博士论文“Architectural Sty ...

  7. 分子模拟软件Schrodinger Suites 2015安装

    安装平台:redhat 5.6 schrodinger 2015 先把schrodinger_2015.iso 挂载到/mnt >>>> mount -o loop schro ...

  8. Ruby On Rails 在线学习好网站

    最好学习Ruby网站: https://ruby-china.org/    我的用户名:19920625lsg,  密码为最常用的 Ruby on Rails 教程 http://railstuto ...

  9. poj: 2739

    挺简单,生成素数表之后建个全素数的vector,然后..随便玩咯 #include <iostream> #include <stdio.h> #include <str ...

  10. JavaOOP QuickHit项目分析

    项目需求:游戏等级6级,随机字符串每级长度不同.每升一级减少比较次数,但是字符串长度相应增加!每级总分数不同,如果游戏中途输入错误则游戏退出!玩家每次在规定时间内输入字符串的同时,打印出游戏难度等级. ...