Libgdx如何获取目录中的文件列表? [英] Libgdx How to get a list of files in a directory?

查看:96
本文介绍了Libgdx如何获取目录中的文件列表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我试图用一个文件handle.list()方法得到一个目录中的文件列表,但即使目录中有文件,它也会返回一个空列表。我觉得奇怪的是,它在设备上工作,但它不能在桌面上工作。我想我知道问题是什么,但我不知道如何解决它。在方法描述中,它说:在桌面上,类路径上一个目录的FileType.Internal句柄将返回一个零长度的数组,但除此之外没有其他方法,所以你们认为我能做什么?解决方案

当在桌面上运行时,内部文件是通过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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆