Re: Incorporating data files into packages and accessing internally



Hi!

Thus spake Todd on 07/31/2007 10:42 PM:
Do I just create a folder within
my structure that holds the data files and then jar in the normal
manner?

You can do that, yes.

Furthermore, I would like to be able to open and read the contents of
the data files within the package without having to know its path on
the disk.

No problem. When your data is located inside the jar that also contains your
application, you can just access it via the application's Classloader.
You'd do something like this:

InputStream is =
this.getClass().getResourceAsStream("/path/inside/jar/data.file");

I would like to think that I can access a data file within
a package in a manner similar to accessing another class in the
package.

That's exactly what getResourceAsStream() does.

HTH,

Phil
.



Relevant Pages

  • Incorporating data files into packages and accessing internally
    ... What I want to do is include the coastal data files into the package ... the data is included with the jar. ... a package in a manner similar to accessing another class in the ...
    (comp.lang.java.programmer)
  • Re: Incorporating data files into packages and accessing internally
    ... the data files within the package without having to know its path on ... put the data in resource, usually gzipped in the jar. ... massage the data so it looks like java source code, ...
    (comp.lang.java.programmer)
  • Re: OT: It aint what it appears to be
    ... power tools and gadgets, "arrr, arrr". ... would not open its twin package. ... Once I even had to call my son-in-law to open a jar ... released the pressure and the lid turns off easily. ...
    (alt.support.mult-sclerosis)
  • Re: What classes are in a package? Functional requirement
    ... you can turn around and check the package for the ... > that correspond to the classpath. ... The JavaBeans spec allows you to package plugins into a jar and you know ... So the creator of the plug-in has to create a special jar file to indicate ...
    (comp.lang.java.programmer)
  • Re: What classes are in a package? Functional requirement
    ... you can turn around and check the package for the ... > that correspond to the classpath. ... The JavaBeans spec allows you to package plugins into a jar and you know ... So the creator of the plug-in has to create a special jar file to indicate ...
    (comp.lang.java.help)