快速业务通道

用java写的一个文件操作类包 - 编程入门网

作者 佚名技术 来源 NET编程 浏览 发布时间 2012-06-19
壓鹸崙猟周議児粥貧?麼勣悶?壓弓拷鹸崙徨朕村貧。    * @param source_name    * @param dest_name    * @param type    * @return    * @throws IOException    */    public int copyDirectory(        String source_name,        String dest_name,        int type        ) throws IOException {      File source_file = new File(source_name);      File dest_file = new File(dest_name);      int result = 0;      Delete del = new Delete(); //喘噐評茅朕村猟周      if(!source_file.exists()||source_file.isFile()) //音贋壓        throw new RuntimeException("DirCopy: no such dir"+source_name);      if(!source_file.canRead()) //音辛響         throw new RuntimeException("DirCopy: source file"+source_name            +"is unreadable");      if(dest_file.exists()) {        if(type==1) {          del.deleteDir(dest_name); //顕固          result = 1;        }        if(type==2) {          result = 2; //音顕固          return result;        }      }      if(!dest_file.exists()) {        new File(dest_name).mkdirs(); //幹秀朕炎朕村        File[] fileList = source_file.listFiles();        for(int i=0;i<fileList.length;i++){          System.out.println(fileList[i].getName());          if(fileList[i].isFile()){            //喘copyFile痕方鹸崙猟周            this.copyFile(                source_name+"/"+fileList[i].getName(),                dest_name+"/"+fileList[i].getName(),                type);          }          else if(fileList[i].isDirectory()){            //弓拷 ---www.bianceng.cn            copyDirectory(                source_name+"/"+fileList[i].getName(),                dest_name+"/"+fileList[i].getName(), type);          }        }        result = 1;      }      return result;    } } package fileOperation; import java.io.BufferedInputStream; import java.io.BufferedOutputStream; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; /** * 鹸崙猟周才猟周斜垢醤窃?嬬登僅坿猟周音贋壓?坿猟周音辛響?朕炎猟周厮将贋壓? * 朕炎揃抄音贋壓?朕炎揃抄音辛亟吉秤趨 * @author wakin * */ public class Copy { /**   * type葎登僅頁倦顕固?1葎顕固症議猟周?2葎音顕固。   * return 議峙葎1燕幣顕固賜宀荷恬屎械頼撹?2葎音顕固?荷恬函?。   * @param source_name   * @param dest_name   * @param type   * @return   * @throws IOException   */ public int copyFile(   String source_name,   String dest_name,   int type) throws IOException {   int result = 0;   int byte_read;   byte [] buffer;   File source_file = new File(source_name);   File dest_file = new File(dest_name);   FileInputStream source = null;   BufferedInputStr

凌众科技专业提供服务器租用、服务器托管、企业邮局、虚拟主机等服务,公司网站:http://www.lingzhong.cn 为了给广大客户了解更多的技术信息,本技术文章收集来源于网络,凌众科技尊重文章作者的版权,如果有涉及你的版权有必要删除你的文章,请和我们联系。以上信息与文章正文是不可分割的一部分,如果您要转载本文章,请保留以上信息,谢谢!

分享到: 更多

Copyright ©1999-2011 厦门凌众科技有限公司 厦门优通互联科技开发有限公司 All rights reserved

地址(ADD):厦门软件园二期望海路63号701E(东南融通旁) 邮编(ZIP):361008

电话:0592-5908028 传真:0592-5908039 咨询信箱:web@lingzhong.cn 咨询OICQ:173723134

《中华人民共和国增值电信业务经营许可证》闽B2-20100024  ICP备案:闽ICP备05037997号