简体   繁体   English

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

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

To rename a file I use 重命名我使用的文件

FileHandle#moveTo(FileHandle dest)

It works fine in most cases. 在大多数情况下,它都能正常工作。 But when I try to rename, for example, a file "abc" to "ABC", the file gets deleted. 但是,当我尝试将文件“ abc”重命名为“ ABC”时,该文件将被删除。 I think the problem is that file names are insensitve ( at least on Desktop, Windows). 我认为问题在于文件名不敏感(至少在台式机,Windows上)。 This is the implementation of the method mentioned above (I left commentaries in the code): 这是上述方法的实现(我在代码中留下了注释):

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();
}

Questions: 问题:

1) Is such behaviour intentional? 1)这种行为是故意的吗? Honestly, it feels wrong. 老实说,感觉不对。

2) Is it ok to do renaming like this (it works in this case, but maybe there are another caveats): 2)可以这样重命名吗?(在这种情况下,它可以工作,但也许还有其他警告):

FileHandle src = ...;
FileHandle dest = ...;
src.file().renameTo(dest.file());

If not, what's the right way? 如果没有,正确的方法是什么?

Update 更新资料

As @exenza suggested, opened an issue on LibGDX issue tracker 正如@exenza所建议的,在LibGDX问题跟踪器上打开了一个问题

On Windows, file names are case insensitive. 在Windows上,文件名不区分大小写。 This means that "abc" and "ABC" refer to the same file. 这意味着“ abc”和“ ABC”指的是同一文件。 Your copyTo() call, will copy the file to itself. 您的copyTo()调用会将文件复制到自身。 Then delete() deletes the file. 然后delete()删除文件。 During all of this there is only one file and no copy. 在所有这些过程中,只有一个文件,没有副本。

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

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