zoukankan      html  css  js  c++  java
  • 实现文件的复制

    package io;
    //实现文件的复制,文件可以包括.jpg .avi .mp2 .ppt等等
    import java.io.File;
    import java.io.FileInputStream;
    import java.io.FileNotFoundException;
    import java.io.FileOutputStream;
    import java.io.IOException;
    
    
    
    public class Copy {
        public static void main(String[] args) {
            long start=System.currentTimeMillis();
            String src="C:\Users\ALHH\Desktop\a04.jpg";
            String dest="C:\Users\ALHH\Desktop\a04.jpg";
            copyFile(src,dest);
            long end=System.currentTimeMillis();
            System.out.println(end-start);
        }
    
    
        
        public static void copyFile(String src,String dest){
            File file1=new File(src);
            File file2=new File(dest);
            
            FileInputStream fis=null;
            try {
                fis = new FileInputStream(file1);
            } catch (FileNotFoundException e) {
                
                e.printStackTrace();
            }
            FileOutputStream fos=null;
    if(fos!=null){
    try { fos = new FileOutputStream(file2); } catch (FileNotFoundException e) { e.printStackTrace(); } byte[] b=new byte[1024]; int len; try { while((len=fis.read())!=-1){ fos.write(b, 0, len); } } catch (IOException e) { e.printStackTrace(); }finally{ try { fis.close(); } catch (IOException e) { e.printStackTrace(); } }
    }
    if(fis!=null){

    try { fos.close();
     } 

    catch (IOException e)
    { e.printStackTrace(); }
    } }}
  • 相关阅读:
    自动刷新页面
    docker 数据卷管理
    docker container(容器)
    docker images
    docker 设计原理
    hbase数据原理及基本架构
    详谈kafka的深入浅出
    django介绍及路由系统
    mysql爱之深探测
    mysql数据库内容相关操作
  • 原文地址:https://www.cnblogs.com/alhh/p/5512809.html
Copyright © 2011-2022 走看看