java .properties 读取配置信息

注意,.properties文件放在根目录即可。

String classpath = Thread.currentThread().getContextClassLoader().getResource("/").getPath();  //获取根目录
  		String fileName = classpath + "truths.properties"; //配置文件名称
  		Properties p = new Properties();
  		FileInputStream fis;
  		try {
  			fis = new FileInputStream(fileName);
  			p.load(fis); //初始化
  			return p.getProperty("server"); //key名称
  		} catch (Exception e) {
  			e.printStackTrace();
  		}


防止中文乱码以及防止%20 发生惨案.

String classpath = Thread.currentThread().getContextClassLoader().getResource("/").getPath();  
  			classpath = URLDecoder.decode(classpath,"UTF-8 ");   //liunx 环境下,防止" " 转化为%20 而路径报错  
  			String fileName = classpath + "truths.properties";
  	  		Properties p = new Properties();
  	  		FileInputStream fis = new FileInputStream(fileName);
  	  		//防止中文乱码/.
  			BufferedReader bf = new BufferedReader(new InputStreamReader(fis));  
  			p.load(bf);
  			p.getProperty("server");

简单暴力.     直接使用.

http://blog.csdn.net/buster2014/article/details/42045225

http://www.lai18.com/content/2659688.html 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值