InputStream/InputStreamReader/maybe path... I'm not sure.

Reading all the documentation, I can't find a reason why the following code works only when I give it a relative path. (canonical fails) Yes, I'm sure the file exists, and is where I think it is. I've even done a .exists using the canonical path, and this method still fails. Any idea's?

Re: InputStream/InputStreamReader/maybe path... I'm not sure.

getResource gets a resource path relative either to the associated class, or to the execution root (eg the "top" of a jar file) if it starts with a "/".
So passing in an absolute path into it will invariably result in a null resource uri coming back.

Re: InputStream/InputStreamReader/maybe path... I'm not sure.

Originally Posted by Tolls

getResource gets a resource path relative either to the associated class, or to the execution root (eg the "top" of a jar file) if it starts with a "/".
So passing in an absolute path into it will invariably result in a null resource uri coming back.

I'm very likely misunderstanding you. I try sending that method a String holding the canonical path to the file.
ie "C:\Eclipse\workspaceZero\Project\Custom Lessons\LS4_test1.aclf"
Since canonical pathes start with the drive letter, (in my case C:) I don't get where the problem would be. I've even tried converting to a Path and using .relativize(). One difference I do see is that when I construct the path for the "known" lessons, I use "/", and not "\", but those paths don't start with a "/".
Oh! OK, I see your meaning now. If I use getResource, or getResourceAsStream, I need to include the path from where the method is to C:, and then it should work. So what's the easy way to do that, or is there one? Or just don't bother making the file a resource at all? What did I read... getResource somehow records that file/resource into the java app's buildpath? Is that right?

Re: InputStream/InputStreamReader/maybe path... I'm not sure.

As I said, you;re using getResource, which gets the thing you asked for relative to the class or application.
So if you pass in the above then it will look in:
<your application directory/jar>/<package your class is in>/C/Eclipse/...etc etc

Keep the file as a resource, assuming it's a core part of the application, and use a relative path to it.
Ensure eclipse knows this file is part of the application, which is easy enough to do by simply ensuring it's in a source folder, so it will be copied over to the correct spot when the app is built. When eclipse jars up the application then it should add this resource in the correct spot.