爪哇一角

          共同探討STRUTS#HIBERNATE#SPRING#EJB等技術
          posts - 3, comments - 6, trackbacks - 0, articles - 99
            BlogJava :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理

          properties文件讀入

          Posted on 2009-06-12 11:20 非洲小白臉 閱讀(174) 評論(0)  編輯  收藏 所屬分類: 其他資源
          package test;

          import java.util.*;
          import java.io.*;


          public class test {

           
          public String getPara(String fileName) {
            Properties prop 
          = new Properties();
            
          try {
             InputStream is 
          = getClass().getResourceAsStream(fileName);
             prop.load(is);
             
          if (is != null)
              is.close();
            }
           catch (Exception e) {
             System.out.println(e 
          + "file " + fileName + " not found");
            }

            
          return prop.getProperty("db");
           }


           
          public static void main(String[] args) {
            test test 
          = new test();
            System.out.println(test.getPara(
          "db.properties"));
           }

          }


          java文件同級目錄下建立db.properties,
          內容  db=123445

          主站蜘蛛池模板: 讷河市| 元氏县| 诏安县| 道真| 郑州市| 定兴县| 平陆县| 五台县| 泸西县| 阜宁县| 泸水县| 奇台县| 丰原市| 丰顺县| 崇礼县| 鞍山市| 陆河县| 板桥市| 盐池县| 密山市| 神池县| 右玉县| 翼城县| 苏州市| 青田县| 南京市| 铜川市| 文山县| 宝丰县| 太和县| 新安县| 济阳县| 清原| 西充县| 漠河县| 离岛区| 普定县| 新巴尔虎左旗| 乐业县| 炎陵县| 吉安市|