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(); }
    } }}
  • 相关阅读:
    【2020-11-16】就是自己的松散意识在作怪
    JQuery 事件
    JQuery DOM 有关代码练习
    JQuery中的DOM操作
    主题简介 ASP .NET
    JQuery 选择器 *很重要 多记
    JQuery 基础
    Ajax 获取数据代码
    Ajax 介绍
    JavaScript 基础二
  • 原文地址:https://www.cnblogs.com/alhh/p/5512809.html
Copyright © 2011-2022 走看看