[EDIT: hierarchy of project have the spaces removed for some strange reason, hopefully the way I've named them makes it clear]
A nice general question which as actually pretty difficult to solve using Google. I've tried searching for multiple things, but all examples of what I'm looking for don't include this case, here's my problem:
I have a 'resources' text file that currently sits inside its own package, my project hierarchy is as follows:
Project
cardPackage
aCardClass
anotherCardClass
mainPackage
mainClass
screenDrawingClass
resourcePackage
resources.txt
A method inside one of my card classes accesses the resources.txt and reads each line. It iterates through the lines until it finds the keyword that marks the start of that certain card's data, and then reads the following lines storing that data into the instance variables of the card. As it stands at the moment, I read the file with a FileReader, and include the entire path to reach the text file (which is inside the workspace/project/package/ location at the moment - using Eclipse IDE). This however needs to be changed eventually, as I'd (eventually) like to make this game playable on more than my own system, and therefore need to use an install path.
Due to this, I suppose I need an OS-path independent way of accessing resources.txt. While testing (and before settling with using the long path method I'm currently using) I used the getResource function, and accessed it through the main class using:
File file = new File(Main.class.getResource("resources.txt");
For this, I put the text file in the same package as the main class. The only problem with this is that there will very likely be much more resource files being used in the future, and it seems coherent to separate them from the rest of the code. If there is a similar method to getResource that can find the file through the package it is in, rather than looking in the same directory as a Class, that would be brilliant, but unfortunately I don't know of one.
Any ideas you guys have would be massively appreciated! What would you do in my situation?
Thanks for taking the time to read
M3ssy