Reputation:
I have switched over to Netbeans and am finding accessing files in packages quite perplexing. Usually I would just have everything in the one folder.
I have created packages in my project which is structured like so:
project_name
......Source Packages
............Game
............Players
............Resources
..................Levels
..................Images
I want to access a text file that resides in the Resources.Levels package from my Gui class which resides in my Game package. How would I do this? Ideally I want to create a String = "mapFile.txt"
Thanks
Upvotes: 1
Views: 1578
Reputation: 692171
This has nothing to do with NetBeans, but everything to do with Java. To access a resource in the classpath, you should use Class.getResourceAsStream()
method. Read its documentatino carefully. In your case, you should use
Gui.class.getResourceAsStream("/Resources/Levels/mapFile.txt");
Also, packages in Java should be in all lowercase.
Upvotes: 2