我在使用renameTo()时遇到了一个奇怪的问题。我不知道为什么我不能重命名为/mnt/desttest
,但可以重命名为/home/kit.ho/desttest
。但是,我已经将每个写入权限授予/ mnt /。返回值是错误的,没有具体原因。谁知道原因?如何将文件重命名为其他文件系统?
import java.io.File;
public class renameFile {
public static void main(String[] args) {
File sourceFile = new File("/home/kit.ho/test");
File targetFile1 = new File("/mnt/desttest");
System.out.println("source file is exist? " + sourceFile.exists() + ", source file => " + sourceFile);
System.out.println(targetFile1 + " is exist? " + targetFile1.exists());
System.out.println("rename to " + targetFile1 + " => " + sourceFile.renameTo(targetFile1));
System.out.println("source file is exist? " + sourceFile.exists() + ", source file => " + sourceFile);
}
}
编辑: 最后,基于一些答案,重命名功能不跨文件系统工作,有没有通过调用像“MV”外部命令对这个问题的任何解决方法吗?
'/ mnt'是一个单独的分区吗? –
你可以'mv /home/kit.ho/test/mnt/stesttest'没有问题吗? – Martin
@Mechanical:yes/mnt位于单独的分区上。 –