We are using temp directory to download some files from multiple machines and then we have to move it to another directory, is there a way to do that without making 2 copies of the files because the files can be as large as 25 gb so can cause disk space issues, we were thinking something like atomic move which would help move the files one at a time without using 2x space
Asked
Active
Viewed 122 times
1
-
3Are you aware of Files.move ? https://docs.oracle.com/javase/7/docs/api/java/nio/file/Files.html#move(java.nio.file.Path,%20java.nio.file.Path,%20java.nio.file.CopyOption...) – racraman Oct 04 '22 at 08:35
-
3Or File.renameTo ? https://docs.oracle.com/en/java/javase/12/docs/api/java.base/java/io/File.html#renameTo(java.io.File) – racraman Oct 04 '22 at 08:43
-
1How about downloading the files to the intended target location in the first place? – Holger Oct 04 '22 at 11:10
-
Does this answer your question? [How to atomically rename a file in Java, even if the dest file already exists?](https://stackoverflow.com/questions/595631/how-to-atomically-rename-a-file-in-java-even-if-the-dest-file-already-exists) – Peter Cordes Oct 05 '22 at 05:12
-
And more simply for just renaming without guaranteed atomicity, [How to rename an existing file?](https://stackoverflow.com/a/14970379) quotes the docs for `File.renameTo`. See also [Rename a file using Java](https://stackoverflow.com/q/1158777) – Peter Cordes Oct 05 '22 at 05:14
-
@racraman Does filles.move use 2x space at any given point of time ? – ARNAV RAJPAL Oct 06 '22 at 06:39
-
@ARNAVRAJPAL definitely NOT if you call it with the ATOMIC_MOVE option, and it will basically default to that option of it is physically possible to do so (ie so long as target is on the same “disc” as the source). Basically, you can assume that ultimately Java will end up calling the same “move file” operating system routine that is invoked when you manually move a file by click+drag in your windows. – racraman Oct 06 '22 at 21:54