This week's book giveaway is in the Java in General forum.
We're giving away four copies of Helidon Revealed: A Practical Guide to Oracle’s Microservices Framework and have Michael Redlich on-line!
See this thread for details.
  • 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
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

location of a property file

 
Ranch Hand
Posts: 135
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi!
I just can't seem to get this darn thing working!
I have a .properties file that I created, and I wasn't sure where to put it so I put it in the folder where I keep my regular html files. I did this because I need to be able to call it, and I figured I could just do this:
"http://keoki.ncr.pwgsc.gc.ca:8080/myfile.properties"
With my regular html files, anything after the "/" is looked for in this particular folder. Right?
Is this what's supposed to be done? Why can't anything be read off the file?
Thanks again,
Annette
 
mister krabs
Posts: 13974
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Are you talking about the db.properties file in the program sample that I gave you? If so, that can go in any directory but you must pass in that directory when you invoke the connectToDatabase() method.
 
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Not too sure what the problem is, but this is a method I use often to load a properties file from the filesystem:

It can obviously be improved, but as long as the directory that contains the properties file is a directory listed in your classpath, you application will be able to find it.
 
Ranch Hand
Posts: 124
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This one ticked me off for a long time until I finally read it in
java spec., I think! If you just want to get a list of properties
in the file and use it somewhere in your java program then why don't you use java.util.ResourceBundle? It's much more convenient and easy to use.
If test.properties is a top class (not in a package):
ResourceBundle rb = ResourceBundle.getBundle("test.properties>);
If test.properties is in the same package as the class accessing it:
ResourceBundle rb = ResourceBundle.getBundle("test.properties>);
If test.properties is in a package named com.mypackage and you are accessing it from some other package:
ResourceBundle rb = ResourceBundle.getBundle("com/mypackage/test.properties>);
To get a property:
String propValue = rb.getString("propertyName");
Much more easier, ain't it?
 
author
Posts: 3252
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Nick Heudecker:
Not too sure what the problem is, but this is a method I use often to load a properties file from the filesystem:


If this properties file is part of a J2EE web-app then Servlet.getServletConfig().getServletContext().getResource*() is more appropriate, I think.
- Peter

 
The only taste of success some people get is to take a bite out of you. Or this tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic