拷贝文件的Java源代码
2008-01-05 10:48:16 来源:WEB开发网 闂傚倸鍊搁崐鎼佸磹閹间礁纾归柟闂寸绾惧綊鏌熼梻瀵割槮缁惧墽鎳撻—鍐偓锝庝簻椤掋垺銇勯幇顖毿撻柟渚垮妼椤粓宕卞Δ鈧獮濠勭磽閸屾艾鈧懓顫濋妸鈺佺疅缂佸顑欓崥瀣煕椤愵偅绶氱紓鍐╂礋濮婂宕掑▎鎴М濠电姭鍋撻梺顒€绉甸幆鐐哄箹濞n剙濡肩紒鎰殜閺屸€愁吋鎼粹€茬敖婵炴垶鎸哥粔鐢稿Φ閸曨垰鍐€妞ゆ劦婢€濞岊亪姊虹紒妯诲蔼闁稿海鏁诲濠氭晲婢跺﹤宓嗛梺缁樺姈缁佹挳宕戦幘璇叉嵍妞ゆ挻绋戞禍鐐叏濡厧浜鹃悗姘炬嫹

核心提示://---Class CopyFile Begin-//Class CopyFile//CopyRight:Writed By Yun-Fengsheng //Last modify time:2001-11-16//Method: public boolean copy(String from_filename,St
//-----------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-----------
赞助商链接