文件拷貝程序

import java.io.*;
public class FileCopy
{
  FileInputStream FIS;
  FileOutputStream FOS;
  public boolean copyFile(String src, String des)
  {
    try
    {
      //取得輸入出流
      FIS = new FileInputStream(src);
      //取得輸出流
      FOS = new FileOutputStream(des);
      //生成一個綬沖區
      byte[] bt = new byte[1024];
      int readNum = 0;
      while ((readNum = FIS.read(bt)) != -1)
      {
        //將輸入流寫到輸出流
        FOS.write(bt, 0, bt.length);
      }
      FIS.close();
      FOS.close();
      return true;
    }
    catch (Exception e)
    {
      try
      {
        FIS.close();
        FOS.close();
      }
      catch (IOException f)
      {
        e.printStackTrace();
      }
      return false;
    }
    finally
    {
    }
  }
  //調用
  public static void main(String[] arg)
  {
    FileCopy fc=new FileCopy();
    if(fc.copyFile("123.rar","456.rar"))
    {
      System.out.println(" File Copy Successfully!");
    }
  }
}

你可能感兴趣的:(exception,String,Class,import,byte,BT)