Java Utililty Methods Properties Load from File

List of utility methods to do Properties Load from File

Description

The list of methods to do Properties Load from File are organized into topic(s).

Method

voidloadSettings(String propertiesFileName)
load Settings
File propertiesFile = new File(HOME_DIR + File.separator + propertiesFileName);
if (propertiesFile.exists()) {
    PROGRAM_SETTINGS.load(new FileInputStream(propertiesFile));
MaploadStrictly(File file)
Loads a Map from a File assuming strings as keys and values.
try {
    return load(file);
} catch (IOException e) {
    throw new RuntimeException(e);
PropertiesloadSystemProperty(String evn, String fileName)
load System Property
String tomcatHome = System.getProperty(evn);
System.out.println("tomcat home:[" + tomcatHome + "]");
String setupFile = tomcatHome + File.separatorChar + "conf" + File.separatorChar + fileName;
System.out.println("system config file:" + setupFile);
Properties prop = new Properties();
InputStream is = null;
try {
    is = new FileInputStream(new File(setupFile));
...
PropertiesloadTestProperties(String filename)
load Test Properties
Properties p = new Properties();
try {
    p.load(new FileInputStream(filename));
} catch (IOException e) {
    p.setProperty("Color.black", "#000000");
    p.setProperty("Color.white", "#FFFFFF");
    p.setProperty("Color.gray", "#808080");
    p.setProperty("Color.beanBackground", "#CCCCCC");
...
StringloadToStringFromFile(String fullFileName)
load To String From File
List<String> lines = loadToStringListFromFile(fullFileName);
if (lines == null)
    return (String) null;
String linebreak = System.getProperty("line.separator", "\r\n");
StringBuilder sb = new StringBuilder();
Iterator<String> it = lines.iterator();
while (it.hasNext()) {
    sb.append(it.next()).append(linebreak);
...
PropertiesloadTrimedProperties(String filename)
load Trimed Properties
Properties properties = new Properties();
properties.load(new FileInputStream(filename));
trimProperties(properties);
return properties;
PropertiesloadUniversal(InputStream in)
Determines if the the input stream is xml if it is, use create properties loaded from xml format, otherwise create properties from default format.
final String xmlDeclarationStart = "<?xml";
BufferedInputStream bin = new BufferedInputStream(in);
bin.mark(4096);
BufferedReader reader = new BufferedReader(new InputStreamReader(bin));
String line = reader.readLine();
boolean isXML = line.startsWith(xmlDeclarationStart);
bin.reset();
Properties props = new Properties();
...
PropertiesloadUserSettings()
load User Settings
String filename = System.getProperty("user.home") + File.separator + ".RacePoint.xml";
Properties result = new Properties();
InputStream in = null;
try {
    in = new FileInputStream(filename);
    BufferedInputStream inBuf = new BufferedInputStream(in);
    result.loadFromXML(inBuf);
    inBuf.close();
...
PropertiesloadWithNormalMode(final String propertyFilePath)
load With Normal Mode
Properties props = new Properties();
props.load(new FileInputStream(propertyFilePath));
return props;
voidloadWithTrimmedValues(InputStream iStr, Properties prop)
Read a set of properties from the received input stream, strip off any excess white space that exists in those property values, and then add those newly-read properties to the received Properties object; not explicitly removing the whitespace here can lead to problems.
Properties p = new Properties();
p.load(iStr);
for (java.util.Enumeration propKeys = p.propertyNames(); propKeys.hasMoreElements();) {
    String tmpKey = (String) propKeys.nextElement();
    String tmpValue = p.getProperty(tmpKey);
    tmpValue = tmpValue.trim();
    prop.put(tmpKey, tmpValue);
return;