• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

? load resources from a classpath folder(outside archive)

 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi everyone,

Is it possible to dynamically load a resource, like a java .properties file, when that file is just sitting by itself in a folder that's in the class path(such as a lib folder)? I'd like to get to it without stuffing it into a .jar and without hard-coding a disk path to it.
Thanks!

+Application
+src
-lib
here.properties
ArchivedResources.jar
+bin
[ September 12, 2008: Message edited by: Chris Riffle ]
 
Ranch Hand
Posts: 139
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It is not adviced to this way. Why don't you load through FileInputStream outside the classpath?
 
Ranch Hand
Posts: 1179
Mac OS X Eclipse IDE
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If the *.properties file is located in the classpath of the application e.g. same folder as the *.class files, inside a jar-file or in a folder that is set up as part of the classpath - then you can read it by using the ResourceBundle or Properties class.

The Properties class can be initialized with an InputStream which you get by calling (if not from a static class)
If you need to initialize it from a static method/block you need to replace "this.getClass()" with the class name of the calling class e.g.
[ September 12, 2008: Message edited by: Rene Larsen ]
 
Chris Riffle
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Rene,

I like the 3rd situation you mentioned where the example.properties file is located in a folder that's included in the class path(not in a .jar)

I did it this way:



where the example.properties file is located in a folder that's included in the classpath


[ September 12, 2008: Message edited by: Chris Riffle ]
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic