Search code examples
javalibgdxrelative-path

Json Relative Path


I use Java and libgdx for my application. I'm currently trying to describe a ui style with a json file, but I must give a path to a texture file. The absolute path is no problem, but how I can use a relative path especially go 2 folders back and then go through a few folders? I tried "../" but it doesn't seem to work.

Thanks for any help.


Solution

  • You go:

    Gdx.files.internal("Path to project");
    

    This will return a File that you can then use in your own ways. If you want to access the "root directory", which is the higher "level", put a / before the path, just like this:

    Gdx.files.internal("/Path/ui.json");