`
uule
  • 浏览: 6307289 次
  • 性别: Icon_minigender_1
  • 来自: 一片神奇的土地
社区版块
存档分类
最新评论

读取配置文件ProPertiesUtil

 
阅读更多
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

public class ProPertiesUtil {
	public static String getValue(String path,String key) {
		String value = "";
		try {
			Properties properties = new Properties();
			InputStream inputStream = ProPertiesUtil.class.getResourceAsStream(path);
			properties.load(inputStream);
			if(properties.containsKey(key)){
				value = properties.getProperty(key);
			}
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return value;
	}
	
	
	public static void main(String[] args) {
		System.out.println(ProPertiesUtil.getValue("/server.properties", "serverUrl"));
	}
}

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics