java copy文件

来源:互联网 发布:淘宝客服绩效管理流程 编辑:程序博客网 时间:2024/06/06 10:39
  1. import java.io.FileInputStream;  
  2. import java.io.FileOutputStream;  
  3. import java.io.IOException;  
  4. /** 
  5.  * <p>CopyFile.java</p> 
  6.  * <p>Created on Apr 17, 2009, 4:33:43 PM</p> 
  7.  * <p>Copyright (c) 2007-2009. CUCKOO Workgroup, USTC, P.R.China</p> 
  8.  * @author Ren Jian 
  9.  */  
  10. public class CopyFile {  
  11.     private boolean copy(String fileFrom, String fileTo) {  
  12.         try {  
  13.             FileInputStream in = new java.io.FileInputStream(fileFrom);  
  14.             FileOutputStream out = new FileOutputStream(fileTo);  
  15.             byte[] bt = new byte[1024];  
  16.             int count;  
  17.             while ((count = in.read(bt)) > 0) {  
  18.                 out.write(bt, 0, count);  
  19.             }  
  20.             in.close();  
  21.             out.close();  
  22.             return true;  
  23.         } catch (IOException ex) {  
  24.             return false;  
  25.         }  
  26.     }  
  27. }  
0 0
原创粉丝点击