About the behavior at the time of error of Files.copy (pathA, pathB)

I'm a little addicted to the behavior when Java's Files.copy (pathA, pathB) is an error, so make a note of it.

Files.copy (pathA, pathB) is an API that copies file A to file B. When executed, the following error occurs.

Copy error


java.nio.file.NoSuchFileException: \pathA-> \pathB

The file at pathA does not exist! ?? I thought, and when I actually checked the destination folder indicated by the file path, the file existed. Why do I get an error saying "doesn't exist" when it exists! ?? Because I thought, I was addicted to it. .. ..

After trying that trick, check the javaDoc in Files.copy (pathA, pathB) properly. Then

JavaDoc (excerpt) from Files.copy (Path source, Path target)

By default, unless the source and target are the same file (in which case this method exits without copying the file), a copy of the target file if it already exists or is a symbolic link. Will fail.

a. What is the target file path! ?? Finally notice!

When I tried to open the folder indicated by pathB, I found that the last directory in the path did not exist! !!

This lesson

Confirmation of the existence of the pass is accurate! Understand the API specifications for the API to be used!

I would like to be careful in the future. .. ..

Recommended Posts

About the behavior at the time of error of Files.copy (pathA, pathB)
[Rails] About Uglifier :: Error: Unexpected token: at the time of deployment
About the behavior of ruby Hash # ==
About the error message Invalid redeclaration of'***'
Speed comparison at the time of generation at the time of date conversion
[JavaScript] I can't get the response body at the time of error with axios (ajax)
About the handling of Null
About the default behavior of decimal point rounding using java.text.NumberFormat
About the basics of Android development
About error handling of comment function
About the role of the initialize method
Think about the 7 rules of Optional
Summary about the introduction of Device
What you are doing in the confirmation at the time of gem update
The unrecognized selector sent to instance error also appears at this time.
Email sending function with Action Mailer at the time of new registration
[Rails] What to do when the Refile image is not displayed when writing the processing at the time of Routing Error
About the version of Docker's Node.js image
What is testing? ・ About the importance of testing
About the operation of next () and nextLine ()
About the treatment of BigDecimal (with reflection)
About the number of threads of Completable Future
About the mechanism of the Web and HTTP
Investigate the behavior of JPA transaction timeout
[Java] [Spring] Test the behavior of the logger
[Rails 6] Change redirect destination at the time of new registration / login by devise
[Thymeleaf & Spring] Error caused by not putting / at the end of meta tag
[Heroku] At the time of deployment We're sorry, but something went wrong. Solution