Added loadAndGet().

git-svn-id: https://samskivert.googlecode.com/svn/trunk@1290 6335cc39-0255-0410-8fd6-9bcaacd3b74c
This commit is contained in:
mdb
2003-11-13 00:05:08 +00:00
parent 7c57805a49
commit be88ca37d6
@@ -1,5 +1,5 @@
//
// $Id: PropertiesUtil.java,v 1.6 2002/03/03 16:01:47 mdb Exp $
// $Id: PropertiesUtil.java,v 1.7 2003/11/13 00:05:08 mdb Exp $
//
// samskivert library - useful routines for java programs
// Copyright (C) 2001 Michael Bayne
@@ -20,6 +20,10 @@
package com.samskivert.util;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.Enumeration;
import java.util.Properties;
@@ -110,4 +114,26 @@ public class PropertiesUtil
dest.put(name.substring(preflen), source.getProperty(name));
}
}
/**
* Loads up the supplied properties file and returns the specified
* key. Clearly this is an expensive operation and you should load a
* properties file separately if you plan to retrieve multiple keys
* from it. This method, however, is convenient for, say, extracting a
* value from a properties file that contains only one key, like a
* build timestamp properties file, for example.
*
* @return the value of the key in question or null if no such key
* exists or an error occurred loading the properties file.
*/
public String loadAndGet (File propFile, String key)
{
try {
Properties props = new Properties();
props.load(new FileInputStream(propFile));
return props.getProperty(key);
} catch (IOException ioe) {
return null;
}
}
}