I need to copy an entire directory containing files inside using Java NIO2
with FileChannels
. But I can only copy the files into the directory.
Here is the code I'm using to copy the files:
public static void copiaDestino(File destino, File origem) throws IOException{
FileChannel inChannel = new FileInputStream(origem).getChannel();
FileChannel outChannel = new FileOutputStream(destino).getChannel();
try{
int maxCont = (64 * 1024 * 1024) - (32 * 1024);
long size = inChannel.size();
long position = 0;
while (position < size){
position += inChannel.transferTo(position, size, outChannel);
}
}finally{
if(inChannel != null){
inChannel.close();
}
if(outChannel != null){
outChannel.close();
}
}
}
}