`
chengyu2099
  • 浏览: 459796 次
  • 性别: Icon_minigender_1
  • 来自: 南京
社区版块
存档分类
最新评论

读取 properties

 
阅读更多
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.util.Properties;

import com.huawei.ecc.constant.SystemCode;


public class ReadServerProperties {
	public static void main(String[] args) {
		System.out.println("*********************");
		String path = Thread.currentThread().getContextClassLoader().getResource("").getPath();
		try {
			path = URLDecoder.decode(path, "utf-8");
			System.out.println("path = " + path);
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
		}
		Properties properties = new Properties();
		String filePath = path + "/server.properties";
		File file = new File(filePath);
		if (file.exists()){
			InputStream is = null;
            try
            {
                is = new FileInputStream(file);
                properties.load(is);
               String property = new String(
            		   properties.getProperty("dataSource.driverClassName").getBytes("ISO-8859-1"),
               "utf-8");
               System.out.println("properties = " + property);
            }catch(Exception e){
            	e.printStackTrace();
            }
		}
	}
}



#DataBase
dataSource.driverClassName=oracle.jdbc.driver.OracleDriver
dataSource.url=jdbc:oracle:thin:@。。。。。
dataSource.username=。。。。
dataSource.password=。。。
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics