April 05
Prof. Ismael H. F. Santos -  ismael@tecgraf.puc-rio.br                                                          2
Copiando diretorio -> outro diretorio
npublic void copiaDir(File srcDir, File dstDir) throws
n                                               IOException {
n  if (srcDir.isDirectory()) {         
n    if (!dstDir.exists()) { dstDir.mkdir(); }
n    String[] subDirs = srcDir.list();         
n    for (int i=0; i < subDirs.length; i++) {             
n      copiaDir(new File(srcDir, subDirs[i]),
n                              new File(dstDir, subDirs[i]));
n    }      
n  } else {
n    // Copiando arquivos usando FileChannel
n    FileChannel src= new FileInputStream(src).getChannel();
n    FileChannel dst= new FileOutputStream(dst).getChannel();
n    // Copia o conteúdo e fecha os FileChannels        
n    dst.transferFrom(src, 0, src.size());               
n    src.close(); dst.close();     
n  }  
n}