get String from Properties - Java java.util

Java examples for java.util:Properties File

Description

get String from Properties

Demo Code


//package com.java2s;

import java.util.Properties;

public class Main {
    /**//from   w  ww. jav a2  s.c o m
     * @param prop The Properties set
     * @param key the key used to store this property
     * @param def a default in case the property cannot be retrieved
     */
    public static String getString(Properties prop, final String key,
            final String def) {
        try {
            final String s = prop.getProperty(key);
            return s == null ? def : s;
        } catch (Exception e) {
            return def;
        }
    }
}

Related Tutorials