码迷,mamicode.com
首页 > 编程语言 > 详细

Java 读取properties

时间:2019-03-16 00:27:40      阅读:151      评论:0      收藏:0      [点我收藏+]

标签:rop   void   class   org   read   package   ati   读取   file   

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

标签:rop   void   class   org   read   package   ati   读取   file   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!