问题描述
无视我的上一篇文章,我找到了问题的根源。我正在使用
Disregarding my last post, I've found the source of the problem. I'm using
a.renameTo(b)
当b不存在时。它不存在的原因是因为有一个符号链接,所以如果b是 / usr / name / folder / file
,那么b真的是 / mnt / MountTest
因为符号链接到该目录。
when b doesn't exist. The reason it doesn't exist is because there is a symbolic link so if b is /usr/name/folder/file
, then b really is /mnt/MountTest
because the symlink is to that directory.
所以问题是,是否有另一种方法使用字符串值重命名Java文件?
如果没有,这个重命名程序怎么能以不同方式完成?
So the question is, is there an alternative way to rename a file in Java using a string value?If not, how can this rename procedure be done differently?
推荐答案
重命名会重命名它...如果它位于同一文件系统上。
A rename would rename it... if it were on the same filesystem.
如果renameTo()失败,您需要将其复制到新位置,然后删除原始文件。
If a renameTo() fails, you'll need to copy it to the new location, then delete the original.
这篇关于不使用renameTo()重命名文件 - Java的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!