重命名我使用的文件
FileHandle#moveTo(FileHandle dest)
在大多数情况下,它工作得很好。但是,当我试图重命名文件"ABC“为"abc”时,文件就会被删除。我认为问题在于文件名是愚蠢的(至少在桌面上,Windows上是如此)。这就是上面提到的方法的实现(我在代码中留下了注释):
public void moveTo (FileHandle dest) {
if (type == FileType.Classpath) throw new GdxRuntimeException("Cannot move a classpath file: " + file);
if (type == FileType.Internal) throw new GdxRuntimeException("Cannot move an internal file: " + file);
copyTo(dest); // file is not copied into another file, since "abc" file is the same as the dest "ABC" file
delete(); // and here the "original" file is deleted, but in this case original file equals to dest file, so the file is lost
if (exists() && isDirectory()) deleteDirectory();
}问题:
( 1)这种行为是否故意的?老实说这感觉不对。
( 2)这样重命名可以吗(在这种情况下是可行的,但也许还有另外一些注意事项):
FileHandle src = ...;
FileHandle dest = ...;
src.file().renameTo(dest.file());如果没有,正确的方法是什么?
更新
正如@exenza建议的那样,打开了一个问题 on LibGDX问题跟踪器
发布于 2017-12-12 22:10:23
在Windows上,文件名不区分大小写。这意味着"abc“和"ABC”指的是同一个文件。您的copyTo()调用将文件复制到自身。然后delete()删除该文件。在所有这些过程中,只有一个文件没有副本。
https://stackoverflow.com/questions/47781886
复制相似问题