Buenas pessoal.
Meu codigo roda enquanto a aplicação é executada no eclipse, caso eu gere um .jar a mesma não funciona
segue codigo :
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.nio.channels.FileChannel;
public class testcopiar {
public static void main(String[] args) {
new testcopiar().copiar("/imagen/brasrepublica.jpg","C:/imagem/brasrepublica.jpg");
}
private void copiar(String origem, String destino){
try {
File srcFile = new File(this.getClass().getResource(origem).toURI());
File tgtFile = new File(destino);
FileChannel sourceChannel = new FileInputStream(srcFile).getChannel();
FileChannel targetChannel = new FileOutputStream(tgtFile).getChannel();
sourceChannel.transferTo(0, sourceChannel.size(), targetChannel);
sourceChannel.close();
targetChannel.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
Se alguem puder ajudar fico feliz.