ProperHelper(prop工具类)

package util;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.URL;
import java.net.URLDecoder;
import java.util.Properties;

public class ProperHelper {
	
	public static Properties JdbcProperty = null;
	
	@SuppressWarnings("finally")
	public static Properties getJdbcProperty(){
		try{
			if(JdbcProperty == null){
				InputStream stream = null;
				try{
					URL fileUrl = ProperHelper.class.getResource("/jdbc.properties");
					String filePath = URLDecoder.decode(fileUrl.getFile(),"UTF-8");
					stream = new FileInputStream(filePath);
					JdbcProperty = new Properties();
					JdbcProperty.load(stream);
				}catch(IOException ex){
					ex.printStackTrace();
				    return null;
				}finally{
					if(stream != null){
						stream.close();
						stream = null;
					}
				}
			}
		}catch(Exception e){
			e.printStackTrace();
			return null;
		}finally{
			return JdbcProperty;
		}
	}
	
	
	
	
	
	
	
	

	/**
	 * @param args
	 * @throws IOException 
	 */
	public static void main(String[] args) throws IOException {
		Properties prop = new Properties();
		prop.setProperty("tetx", "my first love");
		OutputStream stream = null;
		try {
			URL fileUrl = ProperHelper.class.getResource("/jdbc.properties");
			String filePath = URLDecoder.decode(fileUrl.getFile(),"UTF-8");
			stream = new FileOutputStream(filePath);
			prop.store(stream, "Copyright (c) Boxcode Studio");
			System.out.println(prop.getProperty("tetx"));
			
		} catch (Exception e) {
			e.printStackTrace();
		}finally{
			if(stream!=null){
				stream.close();
				stream = null;
			}
		}
	}

}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值