[code]// Cria channel na origem
FileChannel oriChannel = new FileInputStream(?Caminho Origem?).getChannel();
// Cria channel no destino
FileChannel destChannel = new FileOutputStream(?Caminho Destino?).getChannel();
// Copia conteúdo da origem no destino
destChannel.transferFrom(oriChannel, 0, oriChannel.size());
// Fecha channels
oriChannel.close();
destChannel.close();[/code]
//Caminho do arquivo original
File pathAtual = new File("/home/linux/a.txt");
//Caminho a ser criado: /home/linux/file/home/linux/
File pathNovo = new File("/home/linux/file/"+pathAtual.getParent());
//Arquivo no novo diretorio : /home/linux/file/home/linux/a.txt
File newArk = new File(pathNovo+"/"+pathAtual.getName());
if(!pathNovo.isDirectory()){
pathNovo.mkdirs();
newArk.createNewFile();
}else{
newArk.createNewFile();
}
FileInputStream inputStream = new FileInputStream(pathAtual);
FileOutputStream outputStream = new FileOutputStream(newArk);
byte[] bs = new byte[(int) pathAtual.length()];
int line = 0;
while((line=inputStream.read(bs)) != -1){
outputStream.write(bs, 0, line);
}
inputStream.close(); outputStream.close();