properties工具类
package rw.util;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Properties;
public class PropertiesUtils {
	/**
	 * 获得src目录下的properties文件的属性
	 * 
	 * @param url properties文件路径
	 * @param property
	 * @return
	 */
	public static String getProperty(String url, String property) {
		Properties pro = getProperties(url);
		String proValue = (String) pro.get(property);
		return proValue;
	}
	
	/**
	 * 根据路径获得Properties对象
	 * @param url
	 * @return
	 */
	public static Properties getProperties(String url){
		InputStream is = null;
		BufferedReader bf = null;
		Properties pro = new Properties();
		try {
			is = PropertiesUtils.class.getClassLoader().getResourceAsStream(url);
			bf = new BufferedReader(new InputStreamReader(is, "utf-8"));
			pro.load(bf);
			
		}catch(Exception e){
			System.out.println(e.getStackTrace());
		}finally {
			if (is != null) {
				try {
					is.close();
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
			if (bf != null) {
				try {
					bf.close();
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
		}
		return pro;
	}
	
}
 
                    
                 
                
            
         
 浙公网安备 33010602011771号
浙公网安备 33010602011771号