1 Replies - 4325 Views - Last Post: 10 January 2005 - 09:53 AM Rate Topic: -----

#1 fightingillini  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 24-December 04

Accessing A Value In A .properties File

Posted 07 January 2005 - 06:51 PM

I'm trying to get a servlet to access a value key in a .properties file. I need to create a object variable that will ask for the value of a specific key in the .properties file.

Does anyone know how this is done?

Thank you!
Is This A Good Question/Topic? 0
  • +

Replies To: Accessing A Value In A .properties File

#2 stdunbar  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 9
  • Joined: 17-December 04

Re: Accessing A Value In A .properties File

Posted 10 January 2005 - 09:53 AM

I'm not positive I follow you. In general to read a .properties file you will do something like:

import java.util.Properties;
import java.net.URL;

Properties properties = new Properties();
URL url = ClassLoader.getSystemResource("something.properties");
properties.load(url.openStream());

//
// the Properties class is just a HashMap of String, String
// so you can access it with
//
String    value = properties.get( "key" );




Note that the way we've gotten the URL to the properties file requires it to be on the System classpath - i.e. the classpath that existed on startup. This may or may not be what you want in a servlet. It is possible that you'll want it on the webapp classpath.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1