熱點推薦:
您现在的位置: 電腦知識網 >> 編程 >> Java編程 >> Java核心技術 >> 正文

拷貝文件的Java源代碼

2013-11-23 19:01:13  來源: Java核心技術 

  //Class CopyFile Begin
  //Class CopyFile
  //CopyRight:Writed By YunFengsheng
  //Last modify time:
  //Method: public boolean copy(String from_filenameString to_filename)
  class CopyFile
  {
   public boolean copy(String fileString file)
   {
   try //must try and catchotherwide will compile error
     {
   //instance the File as file_in and file_out
   javaioFile file_in=new javaioFile(file);
   javaioFile file_out=new javaioFile(file);
   FileInputStream in=new FileInputStream(file_in);
      FileOutputStream out=new FileOutputStream(file_out);
   byte[] bytes=new byte[];
   int c;
   while((c=inread(bytes))!=)
    outwrite(bytesc);
   inclose();
   outclose();
   return(true); //if success then return true
      }
  
    catch(Exception e)
      { 
    Systemoutprintln(Error!);
    return(false); //if fail then return false
      }
   }
  }
  
  //Class CopyFile Example
  /*
  CopyFile copy=new CopyFile();
  boolean copy_ok=py(c:/hellojspc:/hello_backupjsp);
  if(copy_ok)
  {
   outprintln(拷貝成功!);
  }
  else
  {
   outprintln(拷貝失敗!);
  }
  */
  //Class CopyFile End
From:http://tw.wingwit.com/Article/program/Java/hx/201311/26140.html
  • 上一篇文章:

  • 下一篇文章:
  • Copyright © 2005-2013 電腦知識網 Computer Knowledge   All rights reserved.