I got a strange problem on using renameTo(). I don't know why I can't rename to /mnt/desttest
but it is ok to rename to /home/kit.ho/desttest
. However, I already give every write permission to /mnt/. The return value is false while no specific reason. Who knows the reason?
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);
}
}
Edit: Finally, based on some answers, Rename function does not work on across file system, is there any workaround on this issue by not calling external command like "mv"?
You can't do a rename across file systems (partitions).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With