Question: I was listing the files in one folder and then I have to transfer them to another. However, the problem I get is the following ... When trying to paste them to the other folder the path is like E: \ Files, which causes me to generate some kind of file and it does not stick to me like it should . I tried several ways and still can not do it, I leave my code to see if you can help me

```
 Path algo = Paths.get("E:/Files/");
   public void Copy(String origenArchivo, Path algo) {
                Path origenPath = Paths.get(origenArchivo);
                String s = algo.toAbsolutePath().toString();
                System.out.println(s);
                Path destinoPath = Paths.get(s);
                System.out.println(destinoPath);
                String x = destinoPath.toString() + "/";

                Path conv = Paths.get(x);
                System.out.println(conv);
        try {

            Files.copy(origenPath, conv, StandardCopyOption.REPLACE_EXISTING);
               } catch (IOException ex) {
            Logger.getLogger(Metodos.class.getName()).log(Level.SEVERE, null, ex);
        }

    }

 File dir = new File("C:/Users/PC/Desktop/");
        public void TravelToFantasy(File dir) {
        File listFile[] = dir.listFiles();
        if (listFile != null) {
            for (int i = 0; i < listFile.length; i++) {
                if (listFile[i].isDirectory()) {
                    Copy(listFile[i]);
                } else {
                    System.out.println(listFile[i].getPath());
                    System.out.println(destino);
                    this.Copy(listFile[i].getPath(), algo);

                }
            }
        }
         }

```

I was trying to put the "/" to the path Paths.get gets me, but it always ends up leaving me the path as E:\Files

Thanks four you!

Answer: 
You cannot pass a directory to Files.copy.

You don’t need all that conversion to and from strings. Just use [Path.resolve](https://docs.oracle.com/javase/9/docs/api/java/nio/file/Path.html#resolve-java.nio.file.Path-) instead:

```
public void copy(String origenArchivo, Path algo)
throws IOException {
    Path origenPath = Paths.get(origenArchivo);
    Path conv = algo.resolve(origenPath.getFileName());
    Files.copy(origenPath, conv, StandardCopyOption.REPLACE_EXISTING);
}

```

As a side note, the Path/Paths/Files classes are superior to the java.io.File class, because they provide meaningful information if an operation fails. You should not use java.io.File at all:

```
Path dir = Paths.get("C:/Users/PC/Desktop/");

public void TravelToFantasy(Path dir)
throws IOException {
    try (DirectoryStream<Path> listFile = Files.newDirectoryStream(dir)) {
        for (Path file : listFile) {
            if (Files.isDirectory(file)) {
                Copy(file);
            } else {
                System.out.println(file);
                System.out.println(destino);
                this.Copy(file, algo);
            }
        }
    }
}

```
Use java.io.File.separator instead of "/", this will help your code to run any OS.