Libgdx如何获取目录中的文件列表? [英] Libgdx How to get a list of files in a directory?
问题描述
当在桌面上运行时,内部文件是通过classpath找到的,所以没有简单的方法来列出类路径中的一个目录。如果你只是使用桌面进行开发,并不介意一些黑客,你可以搜索./bin/缺少的文件。
像这样:
FileHandle dirHandle;
if(Gdx.app.getType()== ApplicationType.Android){
dirHandle = Gdx.files.internal(some / directory);
} else {
// ApplicationType.Desktop ..
dirHandle = Gdx.files.internal(./ bin / some / directory); (FileHandle entry:dirHandle.list()){
// yadda ...
}
p $ p>
有关更多详细信息,请参阅: http://bitiotic.com/blog/2012/05/15/libgdx-internal-files-hacks/
So I am trying to get a list of files in a directory with a file handle.list() method but it returns an empty list even though there are files in the directory. What seems strange to me is that it does work on the device but it does not work on the desktop. I think I know what the problem is but I dont know how to solve it though. In the method description it says "On the desktop, an FileType.Internal handle to a directory on the classpath will return a zero length array.", but there is no other method than this so what do you guys think I can do?
解决方案The "internal files" are found via the classpath when run on the desktop, so there is no simple way to "list" a directory in the classpath. If you're just using the desktop for development, and don't mind some hacks you can search "./bin/" for the missing files.
Like this:
FileHandle dirHandle; if (Gdx.app.getType() == ApplicationType.Android) { dirHandle = Gdx.files.internal("some/directory"); } else { // ApplicationType.Desktop .. dirHandle = Gdx.files.internal("./bin/some/directory"); } for (FileHandle entry: dirHandle.list()) { // yadda ... }
For a bit more detail, see: http://bitiotic.com/blog/2012/05/15/libgdx-internal-files-hacks/
这篇关于Libgdx如何获取目录中的文件列表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!