首页 > 编程语言 > 详细

java读取配置文件的方式

时间:2014-11-27 12:47:05      阅读:355      评论:0      收藏:0      [点我收藏+]

前段时间想利用spring的@Value注解的方法取得.properties文件的内容, 但是总是取不到值, 论坛发贴各种方法都试了还是没解决, 放上帖子地址: http://bbs.csdn.net/topics/390936459  

等以后解决了会回来更新,希望有谁会的也帮忙看看~


最后换PropertiesLoaderUtils方法了, 简单粗暴: 

public static String getDirPath() {
	Resource resource = null;
	Properties props = null;
	String driverClass = null;
	try {
		resource = new ClassPathResource("/data.properties");
		props = PropertiesLoaderUtils.loadProperties(resource);
		driverClass= (String) props.get("dirPath");
	} catch (IOException e) {
		e.printStackTrace();
	}
	return driverClass;
	
}

 new ClassPathResource("/data.properties"); 此路径为resource文件夹下的根路径.

java读取配置文件的方式

原文:http://blog.csdn.net/hjun01/article/details/41542239

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!