yuyeyi 发表于 2013-1-28 19:31:51

拷贝一个目录(文件)到指定路径

/**   *拷贝一个目录或者文件到指定路径下   *@paramsource   *@paramtarget   */   public void copy(File source,File target) {       File tarpath = new File(target,source.getName());       if(source.isDirectory()){         tarpath.mkdir();         File[] dir = source.listFiles();         for (int i = 0; i < dir.length; i++) {               copy(dir,tarpath);         }       }else{         try {               InputStream is = new FileInputStream(source);               OutputStream os = new FileOutputStream(tarpath);               byte[] buf = newbyte;               int len = 0;               while((len = is.read(buf))!=-1) {                   os.write(buf,0,len);               }               is.close();               os.close();         } catch (FileNotFoundException e) {               // TODO Auto-generated catch block               e.printStackTrace();         } catch (IOException e) {               // TODO Auto-generated catch block               e.printStackTrace();         }       }   } }
页: [1]
查看完整版本: 拷贝一个目录(文件)到指定路径