Perform in eclipse but when I jar not

Asked

Viewed 56 times

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 that mistake

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
  • This folder there, as far as I know, is protected against reading by windows. Nothing without admin permission can overwrite anything within C: Windows folder. Show the error that occurs when executing by starting the jar of a command prompt.

  • Do not add here, click EDIT and add to your question.

  • src is not a valid path. It looks like you are passing, like a string. Probably this src should be a variable with a path, as the variable destination.

  • which command I use to locate the file inside the jar String source = getClass(). getResource("host");

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.