繁体   English   中英

LibGDX FileHandle:重命名文件会删除该文件

[英]LibGDX FileHandle: Renaming a file deletes the file

重命名我使用的文件

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所建议的,在LibGDX问题跟踪器上打开了一个问题

在Windows上,文件名不区分大小写。 这意味着“ abc”和“ ABC”指的是同一文件。 您的copyTo()调用会将文件复制到自身。 然后delete()删除文件。 在所有这些过程中,只有一个文件,没有副本。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM