• 实现文件的复制


    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(); }
    } }}
  • 相关阅读:
    mongodb复制集配置
    replication set复制集
    CentOS 6.5下源码安装MySQL 5.6
    10个最常见的 HTML5 面试题及答案
    Javascript中document.execCommand()的用法
    javascript 准确的判断类型方法
    getUserMedia API
    javascript
    C++ 面试题
    C++
  • 原文地址:https://www.cnblogs.com/alhh/p/5512809.html
Copyright © 2020-2023  润新知