하나의 파일을 삭제하고 이전 파일로 다른 파일의 이름을 바꾸고 싶지만 자바가 던지고있는 것처럼이 파일을 옮길 수 없습니다. java.nio.file.FileAlreadyExistsException
다음은 코드는 내가 Windows 탐색기에서이 파일을 볼 때 또한 축소판이 존재하지만 그것을 열 수 수 없습니다 여기 Files.move 및 Files.copy가 java.nio.file.FileAlreadyExistsException을 던지고 있습니다.
static void swapData(String origFilePath, String tempFilePath) throws IOException{
Path tempPath = FileSystems.getDefault().getPath(tempFilePath);
Path origPath = FileSystems.getDefault().getPath(origFilePath);
try{
String origFileName = null;
File origFileRef = new File(origFilePath);
if(Files.exists(origPath)){
origFileName = origFileRef.getName();
Files.delete(origPath);
if(Files.exists(origPath))
throw new IOException("cannot able to delete original file");
}
if(origFileName != null)
Files.move(tempPath, tempPath.resolveSibling(origFileName), StandardCopyOption.REPLACE_EXISTING);
}catch(IOException e){
throw e;
}
}
를 사용하여 내가
Files.move(tempPath, tempPath.resolveSibling(origFileName), StandardCopyOption.REPLACE_EXISTING);
에 을 잡 오전 예외입니다 니펫을. 나는 그것이 왜 일어나고 있는지 이해할 수 없다. REPLACE_EXISTING을 사용하고 있다면, FileAlreadyExistsException 예외를 던지는 이유는 무엇인가.
또한 분명히 언급되지 않았기 때문에 이전 질문을 편집했습니다.
도와주세요.
아누 즈
** ** 및 ** ** 디렉토리에서 알 수 있습니까? –
이것은 간단한 로컬 파일 시스템 사용 권한 문제가 아닙니까? 나는 길을 뒤섞었나? 'destPath'는 'moveFrom'에 저장됩니다. 어쩌면 맛의 문제 일 수도 있지만 대상이 오히려 대상이되어야합니다 ("moveTo"). ;) ** 권한 관련 : 파일이 열려 있고 사용자가 파일에 액세스하고 대상 디렉토리에 쓸 수있는 권한이 있는지 확인 했습니까? – DoNuT
새롭게 언급 된 질문을 참조하십시오 – aga