I'm not sure why I am getting a '/' instead of a '\', when trying to have code sourced from this article, to read from an images sub-directory within my Eclipse IDE project:
Output DEBUG: path =images/middle.gif
DEBUG: currentPathC:\Documents and Settings\Jon\workspace\DialogDemo\images/middle.gif ...It should be \middle.gif I guess, but in any case why do I get the error shown in the following line? Couldn't find file: images/middle.gif
It seems that similar issues are not intended to be fixed by Sun.
Related articles include this one, and, reference is made to the escape sequences outlined in Core Java Vol I (8th Ed) P.42-43)
have you considered using "images"+File.pathSeparator+"middle.gif"?
(note that the concatenation in this case will likely be managed by the compiler optimization)
David O'Meara wrote:have you considered using "images"+File.pathSeparator+"middle.gif"?
(note that the concatenation in this case will likely be managed by the compiler optimization)
Well, I'm not sure because my File.pathSeparator returns ";", and I'm not sure whether I can change the value from the default:
Class.getResource doesn't take an absolute file path the way you are trying to do. It takes a relative path to the current class and uses / for path separator; starting with / makes it an absolute path (relative to the class path, not the current directory).
And David meant File.separator, not pathSeparator.
Rob Spoor wrote:Class.getResource doesn't take an absolute file path the way you are trying to do. It takes a relative path to the current class and uses / for path separator; starting with / makes it an absolute path (relative to the class path, not the current directory).
And David meant File.separator, not pathSeparator.
So how may Class.getResource help me with reading the relative path to a string? Any code-snippet, because I couldn't figure it out myself.
Rob Spoor wrote:Class.getResource doesn't take an absolute file path the way you are trying to do. It takes a relative path to the current class and uses / for path separator; starting with / makes it an absolute path (relative to the class path, not the current directory).
And David meant File.separator, not pathSeparator.
So how may Class.getResource help me with reading the relative path to a string? Any code-snippet, because I couldn't figure it out myself.
Assuming the images folder is at the root of your class path: