簡體   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