한 폴더에 파일을 나열한 다음 다른 폴더로 파일을 전송해야했습니다. 그러나, 내가 얻는 문제는 다음과 같습니다 ... 다른 폴더에 붙여 넣으려고 할 때 경로가 E : \ Files와 같아서 어떤 종류의 파일을 생성하게하고 그 파일을 나와 같이 붙이지 않아야합니다. 나는 그것을 할 수 없습니다 여전히 여러 가지 방법을 시도하고, 당신이 나에게다른 디렉터리에 파일을 복사하는 방법
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);
}
}
}
}
나는 "/"Paths.get 저를 얻는 경로에 넣어려고 도움을 줄 수 있는지 확인하기 위해 내 코드를 떠나지 만, 항상 내가 E : \ Files 경로를 남기게된다.
고마워 네!
이것은 작동합니다! 많은 VGR 감사, 나는 이해하고 모든 것이 올바르게 작동합니다. – bukkevimli