標籤:get bcf static stream tty roc package ack rdm
package me.ilt.Blog.util;import java.io.File;import java.io.FileInputStream;import java.io.IOException;import java.util.Properties;public class PropertiesUtil {public static String getValue(String key){Properties prop = new Properties();try {//裝載設定檔prop.load(new FileInputStream(new File("src//dbCfg.properties")));} catch (IOException e) {e.printStackTrace();}//返回擷取的值return prop.getProperty(key);}/*public static void main(String[] args) {System.out.println(getValue("dbUser"));}*/} 方法二
package me.ilt.Util;import java.io.IOException;import java.io.InputStream;import java.util.Properties;public class PropertiesUtil {public static String getValue(String key){Properties prop = new Properties();InputStream in = new PropertiesUtil().getClass().getResourceAsStream("/dbCfg.properties");try {prop.load(in);} catch (IOException e) {e.printStackTrace();}return prop.getProperty(key);}}
java擷取properties設定檔值