| |
//-----------class copyfile begin--------- //class copyfile //copyright:writed by yun-fengsheng //last modify time:2001-11-16 //method: public boolean copy(string from_filename,string to_filename) class copyfile { public boolean copy(string file1,string file2) { try //must try and catch,otherwide will compile error { //instance the file as file_in and file_out java.io.file file_in=new java.io.file(file1); java.io.file file_out=new java.io.file(file2); fileinputstream in1=new fileinputstream(file_in); fileoutputstream out1=new fileoutputstream(file_out); byte[] bytes=new byte[1024]; int c; while((c=in1.read(bytes))!=-1) out1.write(bytes,0,c); in1.close(); out1.close(); return(true); //if success then return true } catch(exception e) { system.out.println("error!"); return(false); //if fail then return false } } } //class copyfile example /* copyfile copy1=new copyfile(); boolean copy_ok=copy1.copy("c:/hello.jsp","c:/hello_backup.jsp"); if(copy_ok) { out.println("拷贝成功!"); } else { out.println("拷贝失败!"); } */ //-----------class copyfile end-----------
|
|