【发布时间】:2017-12-12 21:30:52
【问题描述】:
要重命名我使用的文件
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 问题跟踪器上打开了一个 issue
【问题讨论】:
-
您的桌面应用程序在什么操作系统上运行? Android 或 linux
moveTo方法应该可以正常工作,如“abc”!=“ABC”。 Windows 对文件名不区分大小写,afaik -
桌面操作系统是Windows,忘了说。是的,Android 上没有问题。但是感觉还是不对,这样的方法不应该在任何平台上都有预期的行为吗?
-
我同意,在我看来,所有受 LibGDX 操作系统支持的行为应该是相同的。至少它不应该删除 Windows 上的文件,恕我直言。我建议提出一个问题/错误on LibGDX issue tracker。如果你这样做,请在此处发布参考