Quantcast
Channel: Programação - GUJ
Viewing all articles
Browse latest Browse all 33123

Ler um .xml dentro do .jar

$
0
0

@DougF escreveu:

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();
        }
    }
}

Mensagens: 3

Participantes: 2

Ler tópico completo


Viewing all articles
Browse latest Browse all 33123

Latest Images

Trending Articles

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>