I'm trying to copy a file from one directory to another, but I want the call to be blocking so that the program only proceeds execution once the whole file has been transferred.
Currently I'm using Files.copy()
, which uses non-blocking IO and returns instantly. What other options (preferably built into the java standard library) do I have to solve this problem?
Many thanks, Gareth
Files.copy
isn't asynchronous, it doesn't return until the copy is complete.
Normally if a method is asynchronous, the JavaDoc will be very clear about that, and the method will accept some form of callback (a lambda, or an object implementing an interface with a method it'll call, etc.), or return something that can be used to check for completion (or error). Files.copy
doesn't do that, and its Javadoc doesn't say it's asynchronous, so there's no reason to suspect it is. (I just did a quick test to be sure, and it didn't return until the copy was complete.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With