Mybatis学习之读取配置文件(三)

package com.learn.chapter2.test;

import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
import java.util.Properties;

import org.apache.ibatis.io.Resources;

public class ReadXMLandProperties {

	@SuppressWarnings("unused")
	public static void main(String[] args) {
		InputStream cfgStream = null;
		Reader cfgReader = null;
		
		InputStream proStream = null;
		Reader proReader = null;
		
		Properties properties = null;
		
		try{
			//读取配置文件
			cfgStream = Resources.getResourceAsStream("mybatis-config.xml");
			cfgReader = new InputStreamReader(cfgStream);
			
			
			//读取属性文件
			proStream = Resources.getResourceAsStream("jdbc.properties");
			proReader = new InputStreamReader(proStream);
			
			properties.load(cfgStream);
			
			//解密为明文
			properties.setProperty("username", decode(properties.getProperty("username")));
			properties.setProperty("password", decode(properties.getProperty("password")));
			
		}catch (Exception e) {
			// TODO: handle exception
		}
				
		
	}
	
	private static String decode(String str){
		//解密
		return str;
	}

}

你可能感兴趣的:(MyBatis)