기존의 디렉토리 구조를 복사하려고합니다 (파일 내용 자체가 필요 없으며 0 개의 더미 파일이 필요합니다). 그러나 mkdirs()
은 이 IOException
인 원인이되는 필요한 디렉토리를 생성하지 않습니다.java 파일 mkdirs 및 createNewFile이 작동하지 않습니다.
java.io.IOException: The system cannot find the path specified
at java.io.WinNTFileSystem.createFileExclusively(Native Method)
at java.io.File.createNewFile(Unknown Source)
가 나는 또한
File origParentFile = fileToCopy.getParentFile();
File newParent = new File(origParentFile.getCanonicalPath().replace("O:\\", "C:\\xfer\\"));
localVersion = new File(newParent, fileToCopy.getName());
을 시도,하지만 그 중 하나가 작동하지 않았다 :
private static void readAndCopy(File fileToCopy) throws IOException {
File localVersion = new File(fileToCopy.getCanonicalPath().replace("O:\\", "C:\\xfer\\"));
System.out.println("Replicating " + fileToCopy.getCanonicalPath() + " to " + localVersion.getCanonicalPath());
if (fileToCopy.isDirectory()) {
boolean dirCreated = localVersion.getParentFile().mkdirs();
System.out.println(localVersion.getCanonicalPath() + " " + (dirCreated ? "" : "not ") + "created");
if (dirCreated) {
for (File content : fileToCopy.listFiles()) {
readAndCopy(content);
}
}
} else {
if (!localVersion.exists()) {
localVersion.createNewFile();
}
}
}
public static void main(String[] args) throws IOException {
readAndCopy(new File("o:\\MY_SRC_DIR"));
}
오류 메시지는 다음과 같습니다 코드입니다.
어떤 IOException이 발생합니까? 무슨 메시지 야? – EJP
죄송합니다. @EJP, 깜빡했습니다. 업데이트 된 설명을 참조하십시오. –