// Cria channel na origemFileChanneloriChannel=newFileInputStream(?CaminhoOrigem?).getChannel();// Cria channel no destinoFileChanneldestChannel=newFileOutputStream(?CaminhoDestino?).getChannel();// Copia conteúdo da origem no destinodestChannel.transferFrom(oriChannel,0,oriChannel.size());// Fecha channelsoriChannel.close();destChannel.close();
Amigo, a parte de copiar o arquivo é simples, estou com dificuldades para criar as pastas que sao “pais” do Origem, na pasta destino.
N
NeiBorgesF
Sim, eu sei sobre o File.mkdir();
Obrigado pelo link, mesmo assim.
alexvingg
Não conseguir entender oque você quer.
Coloca o que vc já fez de códgio.
E
entanglement
Não é o mkdir (que cria um de cada vez). É o mkdirs (que cria os subdiretórios intermediários). Simplesmente siga o link
N
NeiBorgesF
Hm, sim, o mkdirs funcionou, ele realmente cria as pastas intermediarias.
jweibe
Cara vai me contribuição ai…
//Caminho do arquivo originalFilepathAtual=newFile("/home/linux/a.txt");//Caminho a ser criado: /home/linux/file/home/linux/FilepathNovo=newFile("/home/linux/file/"+pathAtual.getParent());//Arquivo no novo diretorio : /home/linux/file/home/linux/a.txtFilenewArk=newFile(pathNovo+"/"+pathAtual.getName());if(!pathNovo.isDirectory()){pathNovo.mkdirs();newArk.createNewFile();}else{newArk.createNewFile();}FileInputStreaminputStream=newFileInputStream(pathAtual);FileOutputStreamoutputStream=newFileOutputStream(newArk);byte[]bs=newbyte[(int)pathAtual.length()];intline=0;while((line=inputStream.read(bs))!=-1){outputStream.write(bs,0,line);}inputStream.close();outputStream.close();