0

I need to access directory with levels descriptions in my game.

Gdx.files.internal("data/levels");

On Android it works fine, but on desktop levels is not recognized as a directory and also list() returns null. Why it happens and what is the solution? I use maven as my build tool, I've checked that the .jar contains all necessary assets.

I've found hack:

Gdx.files.internal("./bin/data/levels");

but it obviously works only in development environment, which is not satisfactory.

ArcCha
  • 27
  • 1
  • 5

1 Answers1

0

Try Gdx.files.local("data/levels")

See https://code.google.com/p/libgdx/wiki/FileHandling, and note that "internal" files are searched for via the CLASSPATH. Listing "directories" on the classpath is not implemented (and is unlikely to be listed).

P.T.
  • 24,557
  • 7
  • 64
  • 95
  • On desktop it will return directory relative to application working directory, not the one inside jar. I've tested it, assume I have `somefile` packed in my jar inside data dir. `Gdx.files.local("data/somefile").exists()` will return false, while `Gdx.files.internal("data/somefile").exists()` returns true. Why listing directories on classpath is not implemented? Is it a big issue? – ArcCha Nov 08 '13 at 21:55
  • Yeah, listing the contents of a "directory" in a jar file or on the classpath is not supported. I believe the general case is ugly because a "directory" could span multiple entries on the classpath. See http://stackoverflow.com/questions/1429172/how-do-i-list-the-files-inside-a-jar-file/1429275 for some work-arounds. For your Libgdx probably just generate a file that contains the list of files to side-step the issue. – P.T. Nov 09 '13 at 05:15