標籤:預設值 put util div values getc static try private
Java 讀取設定檔工具類
使用 java.util.Properties
import java.io.IOException;import java.io.InputStream;import java.util.Properties;public class PropertiesReader { private static Properties prop; static { reload(); } private static void reload() { prop = new Properties(); try { InputStream inputStream = PropertiesReader.class.getClassLoader().getResourceAsStream("config.properties"); prop.load(inputStream); } catch (IOException e) { e.printStackTrace(); } } /** * 擷取指定的系統屬性值 * * @param key * @return */ public static String getProperty(String key) { return prop.getProperty(key); } /** * 擷取指定的系統屬性值(帶預設值) * * @param key * @param defaultValue * @return */ public static String getProperty(String key, String defaultValue) { return prop.getProperty(key, defaultValue); }}
java 讀取設定檔工具類 (how to read values from properties file in java)