- /*
- *Tochangethistemplate,chooseTools|Templates
- *andopenthetemplateintheeditor.
- */
- packagecn.lsd;
- importjava.io.File;
- importjava.io.FileInputStream;
- importjava.io.FileNotFoundException;
- importjava.io.FileOutputStream;
- importjava.io.IOException;
- importjava.util.logging.Level;
- importjava.util.logging.Logger;
- /**
- *
- *@date2008-11-26
- *@authorlsd
- */
- publicclassCpp{
- privateStringsourceFile;
- privateStringdestFile;
- publicCpp(StringsourceFile,StringdestFile){
- this.sourceFile=sourceFile;
- this.destFile=destFile;
- doCopy();
- }
- privatevoiddoCopy(){
- FileInputStreamin=null;
- FileOutputStreamout=null;
- byte[]buffer=newbyte[102400];
- try{
- in=newFileInputStream(this.sourceFile);
- Filedest=newFile(this.destFile);
- if(!dest.exists()){//目标文件对应的目录不存在,创建新的目录
- intindex=newString(this.destFile).lastIndexOf("/");
- Stringpath=this.destFile.substring(0,index);
- newFile(path).mkdirs();
- }
- out=newFileOutputStream(this.destFile);
- intnum=0;
- while((num=in.read(buffer))!=-1){
- out.write(buffer,0,num);
- }
- }catch(FileNotFoundExceptionex){
- Logger.getLogger(Cpp.class.getName()).log(Level.SEVERE,null,ex);
- }catch(IOExceptione){
- Logger.getLogger(Cpp.class.getName()).log(Level.SEVERE,null,e);
- }finally{
- try{
- if(in!=null)
- in.close();
- if(out!=null)
- out.close();
- }catch(IOExceptionex){
- Logger.getLogger(Cpp.class.getName()).log(Level.SEVERE,null,ex);
- }
- }
- }
- publicstaticvoidmain(String[]args){
- StringsourceFile="d:/颐和园yhy[小新奉献].rmvb";
- StringdestFile="D:/s/sd/1.rmvb";
- longstartTime=System.currentTimeMillis();
- System.out.println("starttocopy");
- Cppc=newCpp(sourceFile,destFile);
- longendTime=System.currentTimeMillis();
- longtime=(endTime-startTime)/1000;
- System.out.println("copyend;cost:"+time);
- }
- }