Bom dia galera,
Estou tentando ler um arquivo .xml que encontra-se dentro do meu .jar, se eu executar o projetinho pelo eclipse funciona normal, mas quando eu crio o jar da erro que não encontra o caminho.
Poderiam me ajudar?
xml esta na raiz do projeto, e eu tenho que copialo para uma pasta especifica.
public static void downloadXml() throws IOException{
File file = new File("tabelas.xml");
File fileDestino = new File(CAMINHO_XML);
copyFile(file, fileDestino);
System.out.println("XML implantado no caminho: " + CAMINHO_XML);
}
private static void copyFile(File origem, File destination) throws IOException, URISyntaxException {
if(destination.exists()){
return;
}
new File(destination.getParent()).mkdirs();
FileChannel sourceChannel = null;
FileChannel destinationChannel = null;
try {
sourceChannel = new FileInputStream(origem).getChannel();
destinationChannel = new FileOutputStream(destination).getChannel();
sourceChannel.transferTo(0, sourceChannel.size(), destinationChannel);
} finally {
if (sourceChannel != null && sourceChannel.isOpen()){
sourceChannel.close();
}
if (destinationChannel != null && destinationChannel.isOpen()){
destinationChannel.close();
}
}
}