首页 > 编程语言 > 详细

Java 读取properties

时间:2019-03-16 00:53:47      阅读:29      评论:0      收藏:0      [点我收藏+]

标签:read   per   cep   red   trac   highlight   ger   ati   rgs   

package Db;
import java.io.InputStream;
import java.util.Properties;
import java.io.BufferedReader;
import org.apache.log4j.Logger;
import java.io.FileReader;
import api.SshTest;

import java.io.IOException;

public class GetProperties {
	private static Logger logger = Logger.getLogger(SshTest.class);
	public static  void readFile() {
		String driver = "";
		String dburl = "";
		String user = "";
		String pwd="";
		BufferedReader bufferedReader=null;
		try {
		bufferedReader = new BufferedReader(new FileReader("F:\\\\eclipse\\\\myproject\\\\src\\\\Db\\\\config.properties"));
		}catch (Exception e) {
					e.printStackTrace();
				}
		Properties p = new Properties();
		try {
			p.load(bufferedReader);
		} catch (IOException e1) {
			e1.printStackTrace();
		}
		
		driver = p.getProperty("Driver");
		dburl = p.getProperty("DBurl");
		user = p.getProperty("DBUser");
		pwd = p.getProperty("DBPwd");
		System.out.println(user+pwd+dburl+driver);
		logger.info(""+driver+""+dburl+""+user+""+pwd);
	}
	public static void main(String[] args) {
		readFile();
	}
//     Properties properties = new Properties();
//	2     // 使用ClassLoader加载properties配置文件生成对应的输入流
//	3     InputStream in = PropertiesMain.class.getClassLoader().getResourceAsStream("config/config.properties");
//	4     // 使用properties对象加载输入流
//	5     properties.load(in);
//	6     //获取key对应的value值
//	7     properties.getProperty(String key);

}

  

Java 读取properties

标签:read   per   cep   red   trac   highlight   ger   ati   rgs   

原文:https://www.cnblogs.com/SunshineKimi/p/10540298.html

(0)
(0)
   
举报
评论 一句话评论(0
0条  
登录后才能评论!
© 2014 bubuko.com 版权所有 鲁ICP备09046678号-4
打开技术之扣,分享程序人生!
             

鲁公网安备 37021202000002号