java操作Property

package com.hola.range.common;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Hashtable;
import java.util.Properties;

@SuppressWarnings("unchecked")
public class PropertyUtil {

 public final static Properties sqlProp = new Properties();
 public final static Properties uploadProp = new Properties();
// private static Element root ;
 
 public void initSqlPool(){
  String str = this.getClass().getResource("/com/hola/ehr/resources/sql.properties").getFile();
  FileInputStream fis = null;
  try {
   fis = new FileInputStream(str);
   sqlProp.load(fis);
  } catch (FileNotFoundException e1) {
   e1.printStackTrace();
  } catch (IOException e) {
   e.printStackTrace();
  } finally{
   try {
    fis.close();
   } catch (IOException e) {
    e.printStackTrace();
   }
  }
 }
 
 public void initUpload(){
  String str = this.getClass().getResource("/com/hola/es/resources/upload.properties").getFile();
  FileInputStream fis = null;
  try {
   fis = new FileInputStream(str);
   uploadProp.load(fis);
  } catch (FileNotFoundException e1) {
   e1.printStackTrace();
  } catch (IOException e) {
   e.printStackTrace();
  } finally{
   try {
    fis.close();
   } catch (IOException e) {
    e.printStackTrace();
   }
  }
 }
 
 public void initTriggerCfg(){
//  SAXBuilder sax = new SAXBuilder();
//  Document doc=null;
//  try{
//   String path = this.getClass().getResource("PropertyUtil.class").toString().split("utility")[0]+"ehr/resources/config.xml";
//   InputStream is = new FileInputStream(path.split("file:/")[1]);
//   doc = sax.build(is); 
//   root = doc.getRootElement();
//  }catch(Exception e){
//   e.printStackTrace();
//  }
 }
 
 public static Hashtable getPropertysUtil() {
  Hashtable ht = new Hashtable();
//  try{
//   if(root !=null){
//    for(int i=0;i<root.getChildren().size();i++){
//     Element el = (Element) root.getChildren().get(i);
//     ht.put(el.getName(), el.getText());
//    }
//   }
//  }catch(Exception e){
//   e.printStackTrace();
//  }
  return ht;
 }
 
 public static String getProp(String key,String name){
  String str = "";
  if(name.equals("sql")){
   str = PropertyUtil.sqlProp.getProperty(key);
  }else if(name.equals("upload")){
   str = PropertyUtil.uploadProp.getProperty(key);
  }
  if(str == null){
   PropertyUtil propUtil = new PropertyUtil();
   if(name.equals("sql")){
    propUtil.initSqlPool();
    str = PropertyUtil.sqlProp.getProperty(key);
   }else if(name.equals("upload")){
    propUtil.initUpload();
    str = PropertyUtil.uploadProp.getProperty(key);
   }
  }
  return str;
 }
 
 public static void main(String[] args){
  Double a = 40.0;
  System.out.println(a.toString().split("//.")[0]);
 }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值