RSS
热门关键字:  下载  cms  模版  开源  dedecms
当前位置 :| 主页 > 站长学院 > JSP教程 >

用JAVA实现文件copy的代码示例

来源:互连网 作者:佚名 时间:2006-03-30 Tag: 点击:
你可以自己修改一下,放到你的类里面调用。

/**
* 拷贝一个文件到另一个目录
*/
  public boolean copyFile(String from,String to){

    File fromFile,toFile;
    fromFile = new File(from);
    toFile = new File(to);
    FileInputStream fis = null;
    FileOutputStream fos = null;

    try{
      toFile.createNewFile();
      fis = new FileInputStream(fromFile);
      fos = new FileOutputStream(toFile);
      int bytesRead;
      byte[] buf = new byte[4 * 1024];  // 4K buffer
      while((bytesRead=fis.read(buf))!=-1){
        fos.write(buf,0,bytesRead);
      }
      fos.flush();
      fos.close();
      fis.close();
    }catch(IOException e){
      System.out.println(e);
      return false;
    }
    return true;

  } 
上一篇:中文问题之我见
下一篇:解释如下:
最新评论共有 0 位网友发表了评论
发表评论
评论内容:不能超过250字,需审核,请自觉遵守互联网相关政策法规。
用户名: 密码:
匿名?
注册
热点关注
相关文章