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();
    }
  • 相关阅读:
    笔记手动排序
    笔记手动分页
    Spring定时任务Quartz配置之手动设置
    java 日期处理
    SQL Case when 的使用方法
    Hibernate八大类HQL查询集合
    Spring定时任务Quartz配置
    各个浏览器显示版本(IE,火狐)
    js转译html标签
    定时备份SQL SERVER的数据库并且把备份文件复制到另外一台服务器
  • 原文地址:https://www.cnblogs.com/Y-mmeng/p/10606464.html
Copyright © 2011-2022 走看看