• 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

Reading properties file in classpath

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How to read the properties file in classpath.

private static String fileName = "ApplicationConfig.properties";
ClassLoader.getSystemClassLoader().getResourceAsStream(fileName)

I have set classpath variable to :
classpath = D:\ApplicationConfig.properties

But getting error.

Please let me know how to read a properties file in classpath
 
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
An easier way to do this is to use ResourceBundle.getBundle().

If you want to get a resource as a stream, this quote from the JavaDocs might help:


The name of a resource is a '/'-separated path name that identifies the resource

 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Don't put the properties file itself in the classpath, but just the directory that contains the file. So, instead of this:

classpath = D:\ApplicationConfig.properties

use this:

classpath = D:\
 
veda patil
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Both above solution are working fine if i am running the program.
But if i build the exe file and the run the application i am getting :
Caused by: java.util.MissingResourceException: Can't find bundle for base name
pplicationConfig, locale en_US
at java.util.ResourceBundle.throwMissingResourceException(ResourceBundl
.java:804)

Thanks
 
Rancher
Posts: 5008
38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
> if i build the exe file and the run the application

What part of java builds an exe file?
If you are using another application for this then you need to read the doc for that app to see how to use it.
 
author
Posts: 4335
39
jQuery Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I spent like a month researching once this issue as it relates to J2EE jars and it can be frustrating. You can put the properties file inside a JAR, but then the JAR must be specifically named in the class path if it is being used as a utility jar and not the main application.

I tend to use getResourceAsStream() more than RS.getBundle() due to easier naming conventions, although both work just fine. Show the error you get if you use getResourceAsStream() with D:\ as the classpath.
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you so much Jesper de Jong .

my classpath issue was resolved . thanks for the solution
 
reply
    Bookmark Topic Watch Topic
  • New Topic