[英]is FileUtils.moveDirectory(src,dst) safe to move files between directories
I have to move huge files in server from one folder to another, I am using 我必须将服务器中的大文件从一个文件夹移动到另一个文件夹,我正在使用
FileUtils.moveDirectory(src, dst);
This is quick because moveDirectory
just renames the src
to dst
, in some cases where dst
is sub folder of src
, it copies files to dst
and removed from src
(which will never happen in my case dst
is never subdirectory of src
). 这是快速的,因为
moveDirectory
只是将src
重命名为dst
,在某些情况下dst
是src
子文件夹,它将文件复制到dst
并从src
删除(在我的情况下, dst
永远不会是src
子目录)。
Now, is there a chance that FileUtils.moveDirectory(src, dst);
现在,
FileUtils.moveDirectory(src, dst);
fails, if yes, will I have my files in source ? 失败,如果是,我将在源文件中保存文件吗? because this is the only copy and I cannot loose files.
因为这是唯一的副本,所以我不能丢失文件。 Either completely move to
dst
or just fail and leave my files at src
. 要么完全转移到
dst
要么要么失败,然后将我的文件保留在src
。
Short answer: Yes; 简短的回答:是的; even if something goes wrong, the files will be in
src
. 即使出现问题,文件也将位于
src
。
At a low level the action is copy and then delete, rather than rename. 在较低级别上,操作是复制然后删除,而不是重命名。 That way the code can insure that in no case will things be deleted before being moved;
这样,代码可以确保在任何情况下都不会在移动之前删除所有内容。 conceptually this means that the file may not exist in the
dest
(out of disk space), or may exist both at src
and dest
(delete permission denied), but never missing. 从概念上讲,这意味着文件可能不存在于
dest
(磁盘空间不足),或者可能同时存在于src
和dest
(拒绝删除权限),但永远不会丢失。 Also means that for a short period of time you'll be using 2x the disk space, so bear that in mind. 这也意味着在短时间内您将使用2倍的磁盘空间,因此请记住这一点。
Source code for FileUtils : see line 2881 FileUtils的源代码:请参见2881行
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.