java操作Property

    技术2025-09-20  127

    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]); }}

    最新回复(0)