Added loadAndGet().
git-svn-id: https://samskivert.googlecode.com/svn/trunk@1290 6335cc39-0255-0410-8fd6-9bcaacd3b74c
This commit is contained in:
@@ -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
|
// samskivert library - useful routines for java programs
|
||||||
// Copyright (C) 2001 Michael Bayne
|
// Copyright (C) 2001 Michael Bayne
|
||||||
@@ -20,6 +20,10 @@
|
|||||||
|
|
||||||
package com.samskivert.util;
|
package com.samskivert.util;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileInputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
import java.util.Enumeration;
|
import java.util.Enumeration;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
|
||||||
@@ -110,4 +114,26 @@ public class PropertiesUtil
|
|||||||
dest.put(name.substring(preflen), source.getProperty(name));
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user