我目前正在尝试使用命令开发文件资源管理器程序(如CMD thingy)。我在尝试复制文件夹时遇到错误,但我找不到问题。
public class Action {
public static void copy(String srcDestination, String desDestination) throws IOException{
Scanner userEntry= new Scanner(System.in);
String userInput;
String sSource=srcDestination;
String sDesignated=desDestination;
Path pSource = Paths.get(sSource);
Path pDesignated = Paths.get(sDesignated);
File fSource= new File(sSource);
File fDesignated= new File(sDesignated);
if(!fSource.exists()){
System.out.println("Source directory does not exist!");
}
else if (!fDesignated.exists()){
System.out.println("Destination directory does not exist! Would you like to create it now? Y/N");
userInput=userEntry.nextLine();
if(userInput.equals("Y")||userInput.equals("y")){
fDesignated.mkdir();
}
Files.copy(pSource, pDesignated, StandardCopyOption.COPY_ATTRIBUTES);
}
Files.copy(pSource, pDesignated, StandardCopyOption.COPY_ATTRIBUTES);
System.out.println("Done");
}
}
我得到的错误
Exception in thread "main" java.nio.file.FileAlreadyExistsException: E:\destFOLDER at sun.nio.fs.WindowsFileCopy.copy(WindowsFileCopy.java:123)
at sun.nio.fs.WindowsFileSystemProvider.copy(WindowsFileSystemProvider.java:278)
at java.nio.file.Files.copy(Files.java:1225)
at pm.entitymanager.logic.file.Action.copy(Action.java:55)
at pm.entitymanager.logic.file.ApplicationLogic.main(ApplicationLogic.java:64)
Java结果:1