/* * To change this template, choose Tools | Templates * and open the template in the editor. */ package cn.lsd; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.util.logging.Level; import java.util.logging.Logger; /** * * @date 2008-11-26 * @author lsd */ public class Cpp { private String sourceFile; private String destFile; public Cpp(String sourceFile,String destFile){ this.sourceFile = sourceFile; this.destFile = destFile; doCopy(); } private void doCopy() { FileInputStream in =null; FileOutputStream out =null; byte[] buffer = new byte[102400]; try { in = new FileInputStream(this.sourceFile); File dest = new File(this.destFile); if(!dest.exists()){//目標文件對應的目錄不存在,創建新的目錄 int index = new String(this.destFile).lastIndexOf("/"); String path = this.destFile.substring(0, index); new File(path).mkdirs(); } out = new FileOutputStream(this.destFile); int num =0; while((num=in.read(buffer))!=-1){ out.write(buffer,0,num); } } catch (FileNotFoundException ex) { Logger.getLogger(Cpp.class.getName()).log(Level.SEVERE, null, ex); } catch (IOException e){ Logger.getLogger(Cpp.class.getName()).log(Level.SEVERE, null, e); } finally{ try { if(in!=null) in.close(); if(out!=null) out.close(); } catch (IOException ex) { Logger.getLogger(Cpp.class.getName()).log(Level.SEVERE, null, ex); } } } public static void main(String[] args){ String sourceFile = "d:/頤和園yhy[小新奉獻].rmvb"; String destFile = "D:/s/sd/1.rmvb"; long startTime =System.currentTimeMillis(); System.out.println("start to copy"); Cpp c= new Cpp(sourceFile,destFile); long endTime = System.currentTimeMillis(); long time = (endTime-startTime)/1000; System.out.println("copy end;cost:"+time); } }
JAVA拷貝
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章
mybatis開啓MapperScannerConfigurer導致properties不生效
原創
2024-02-07 13:55:41
Java字符串的一些理解
原創
2023-10-31 09:11:32
(二)java版spring boot 社交電子商務平臺-security簡單使用
原創
2023-10-10 11:05:06
(三)java版spring cloud+spring boot+redis多租戶社交電子商務平臺-Spring Cloud實戰隨機端口
原創
2023-10-10 11:05:04
如何使用 Java 反射?反射的用法及案例
原創
2023-10-10 02:23:57
最新美團面試集合(一面+二面+三面+重點技術面試題)附面試解析
原創
2023-10-10 01:43:49
Java程序員不想被裁員困擾,應該怎樣築基、發展才能越走越遠?
原創
2023-10-10 01:43:34
阿里巴巴Java開發手冊 梳理筆記 - finally 塊必須對資源對象、流對象進行關閉
原創
2023-08-02 10:29:06
java併發-CAS的理解
原創
2023-05-29 01:40:21
java併發-Timer類的使用和原理
原創
2023-03-28 01:52:22
java併發-ReadWriteLock代碼理解
原創
2023-03-28 01:52:20
java併發-synchronized關鍵字
原創
2023-03-28 01:52:18
java併發-AQS總結-原理
原創
2023-03-28 01:52:16
java併發-緩存一致性協議和內存屏障的思考和理解
原創
2023-03-28 01:52:14