zoukankan      html  css  js  c++  java
  • JAVA之用缓冲流读写文件

    public class CopyDemo {
    public static void main(String[] args) throws Exception{
    long time1 = System.currentTimeMillis();
    copy4(new File("d:\ccc.mp4"),new File("e:\ccc.mp4"));
    long time2 = System.currentTimeMillis();
    System.out.println(time2-time1);
    }
    //1.字节流读写单个字节 太慢了
    public static void copy1(File src,File desc) throws Exception{
    FileInputStream fis = new FileInputStream(src);
    FileOutputStream fos = new FileOutputStream(desc);
    int len = 0;
    while ((len=fis.read())!=-1){
    fos.write(len);
    }
    fos.close();
    fis.close();
    }
    //2.字节流读写字节数组 550
    public static void copy2(File src,File desc) throws Exception{
    FileInputStream fis = new FileInputStream(src);
    FileOutputStream fos = new FileOutputStream(desc);
    int len = 0;
    byte[] b = new byte[1024*10];
    while ((len=fis.read(b))!=-1){
    fos.write(b,0,len);
    }
    fos.close();
    fis.close();
    }
    //3.字节流缓冲区 读写单个字节 4252
    public static void copy3(File src,File desc) throws Exception{
    BufferedInputStream bis = new BufferedInputStream(new FileInputStream(src));
    BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(desc));
    int len = 0;
    while ((len=bis.read())!=-1){
    bos.write(len);
    }
    bis.close();
    bos.close();
    }
    //4.字节流缓冲区读写字节数组 585
    public static void copy4(File src,File desc) throws Exception{
    BufferedInputStream bis = new BufferedInputStream(new FileInputStream(src));
    BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(desc));
    int len = 0;
    byte[] b = new byte[1024*10];
    while ((len=bis.read(b))!=-1){
    bos.write(b,0,len);
    }
    bos.close();
    bis.close();
    }
  • 相关阅读:
    转:BIOS的恢复技术之Top Swap的原理应用
    半硬化树脂PP的型号
    PADS常用画板过程
    ad2014注册出现:注册
    CPU处理多任务——中断与轮询方式比较
    PDS常用快捷键
    方法三破解:Excel工作表保护密码
    【Linux指标】内存篇
    mac apt-get--> Homebrew
    20180113Go匿名函数和闭包
  • 原文地址:https://www.cnblogs.com/Y-mmeng/p/10606464.html
Copyright © 2011-2022 走看看