I apologize if this is a duplicate question, but I can't seem to find any solution that work for my issue. I have a program that requires the use of a .txt file. I have successfully used the file if I run from Eclipse using:
But when I export it to a runnable JAR it can't find it. You all have solved this issue for me before for a font file, but I can't seem to figure it out for a normal .txt file. In researching online I have come across this:
But that leaves it as type InputStream, and I need it to be a file. Can anybody help me out with including it in a JAR, or maybe in how to use InputStream to create the File? Thanks in advance.
Yeah disregard the typo in the post, my code doesn't reflect that. I agree it's not included in the JAR, that's the issue I'm having. It needs to be added as a resource I think.. I know this is basic stuff, sorry, I'm trying to get a grip on it here...
Remember that using a relative URL (as both you and Ron did) means that the resource should be in the same folder with the class in the JAR. And when I say "the class" I mean the class where that code is located. If you want to put the resource in the JAR's root folder then use an absolute URL:
I always use the getResource() method of Class, rather than ClassLoader:
At least the API documentation for Class.getResource() has a halfway comprehensible explanation of how the method works, whereas the docs for ClassLoader.getResource() are totally vague. Apparently they work differently. Why that is, I have no idea but it don't impress me much.
So what I said refers to Class.getResource(). Sorry for the confusion.