Java初学习 - 文件的COPY操作

来源:互联网 发布:游戏交易网站源码 编辑:程序博客网 时间:2024/05/28 09:32
[java] view plaincopy
  1. import java.io.FileInputStream;  
  2. import java.io.FileOutputStream;  
  3. import java.io.IOException;  

  4. public class CopyFile {  
  5.     private boolean copy(String fileFrom, String fileTo) {  
  6.         try {  
  7.             FileInputStream in = new java.io.FileInputStream(fileFrom);  
  8.             FileOutputStream out = new FileOutputStream(fileTo);  
  9.             byte[] bt = new byte[1024];  
  10.             int count;  
  11.             while ((count = in.read(bt)) > 0) {  
  12.                 out.write(bt, 0, count);  
  13.             }  
  14.             in.close();  
  15.             out.close();  
  16.             return true;  
  17.         } catch (IOException ex) {  
  18.             return false;  
  19.         }  
  20.     }  
  21. }
0 0
原创粉丝点击