Results 1 to 2 of 2
  1. #1
    todd is offline Member
    Join Date
    Jul 2007
    Posts
    1
    Rep Power
    0

    Default Packaging and accessing data files

    Hello,

    I want to include some standard data files within my class package. I don't want to make these data files into interfaces as that would lead to hard coding (implements ...) which I don't want to use.

    Do I create a folder in my development tree into which I place the data and then package the jar normally?

    Once that is completed, how can I access the data from within the class without having to know the full path on disk of the data file?

    Any help is appreciated.

    Thanks,
    Todd

  2. #2
    brianhks is offline Senior Member
    Join Date
    Jul 2007
    Posts
    135
    Rep Power
    0

    Default

    this.getClass().getClassLoader().getResourceAsStre am("relativePathInJar") is your friend.

    So say the file is config.xml in the conf directory inside your jar file. The command will be:
    this.getClass().getClassLoader().getResourceAsStre am("conf/config.xml");

Similar Threads

  1. Randomly accessing files
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 12-12-2007, 11:46 AM
  2. Accessing index.dat files
    By vissu007 in forum Networking
    Replies: 1
    Last Post: 07-01-2007, 05:47 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •