爪哇一角

          共同探討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

          主站蜘蛛池模板: 丹棱县| 南城县| 西城区| 抚州市| 东宁县| 西丰县| 岗巴县| 翁牛特旗| 嘉黎县| 芮城县| 蓬溪县| 志丹县| 乐陵市| 高雄市| 沽源县| 东平县| 梁平县| 正宁县| 广平县| 东乌珠穆沁旗| 子长县| 离岛区| 北海市| 武宁县| 洪泽县| 铁力市| 华阴市| 区。| 屯昌县| 浏阳市| 鲜城| 禄劝| 揭西县| 金山区| 贡山| 宝山区| 德庆县| 迭部县| 呼图壁县| 普宁市| 神木县|