如何将文件重命名为另一个文件系统?

Kit*_* Ho 3 java rename file

我在使用renameTo()时遇到了一个奇怪的问题.我不知道为什么我不能重命名,/mnt/desttest但可以重命名为/home/kit.ho/desttest.但是,我已经将每个写入权限授予/ mnt /.返回值为false,没有具体原因.谁知道原因?

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);   
    }
}
Run Code Online (Sandbox Code Playgroud)

编辑:最后,基于一些答案,重命名功能不适用于跨文件系统,有没有解决这个问题的方法是不调用像"mv"这样的外部命令?

jdi*_*tal 7

您无法跨文件系统(分区)进行重命名.