Runs in eclipse but when the jar does not

0
package teste;

import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.StandardCopyOption;

import javax.swing.JOptionPane;

public class Mover {

    public static void main(String[] args) throws IOException, InterruptedException {


String destino = "C:"+ File.separator +"Windows"+ File.separator +"system32"+ File.separator +"drivers"+ File.separator +"etc"+ File.separator ;


Path sourceFile = Paths.get("src","hosts");
Path targetFile = Paths.get(destino,"hosts");

Files.copy(sourceFile, targetFile,StandardCopyOption.REPLACE_EXISTING);

 JOptionPane.showMessageDialog( null, "ARQUIVO HOSTS TROCADO.");
}
}

of this error

C:\Users\jerso\Desktop>java -jar trocador.jar
Exception in thread "main" java.lang.reflect.InvocationTargetException
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
        at java.lang.reflect.Method.invoke(Unknown Source)
        at org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader.main(JarRsrcLoader.java:58)

Caused by: java.nio.file.NoSuchFileException: src\hosts
        at sun.nio.fs.WindowsException.translateToIOException(Unknown Source)
        at sun.nio.fs.WindowsException.rethrowAsIOException(Unknown Source)
        at sun.nio.fs.WindowsException.rethrowAsIOException(Unknown Source)
        at sun.nio.fs.WindowsFileCopy.copy(Unknown Source)
        at sun.nio.fs.WindowsFileSystemProvider.copy(Unknown Source)
        at java.nio.file.Files.copy(Unknown Source)
        at pergunta.Mover.main(Mover.java:24)
        ... 5 more
    
asked by anonymous 29.12.2017 / 22:37

0 answers