Re: Java file access
1-crm@freenet.de wrote:
....
I tried:
.getResource("/files/File1.txt")
but this also returns null.
....
If I bind a JAR package .getResource("/files/File1.txt") returns the
expected result ../myfolder/files/File1.txt but only within the jar
package. What am i doing wrong?
You need to look further into what the '/', '.' and '..'
parts of the string mean.
For example, putting '/' at the very beginning of the string
will indicate that the resource path starts from the 'root'.
When run on loose classes in the file-system, the '/'
indicates the *drive* on which they reside, whereas when
running from a Jar file, it indicates the root of the Jar file.
Including the leading '/' works for Jar files, but not (usually)
loose class files.
Or, to put that another way - you need to use slightly different
methods to access loose resources, than you need when
accessing the same resources in a far file.
But then - why is it so important to access resources
*both* ways from within the one project?
Either this project will be run from loose class files
(extremely not recommended) or Jar files. It is not
difficult to generate a Jar file for use during testing.
...Btw: i am using Eclipse ...
That is not relevant to the problem, if I thought it was,
I'd recommend you post to the Eclipse forums.
Andrew T.