<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    posts - 14,  comments - 37,  trackbacks - 0
    以下這個類是在JAVA中如何讀取Properties配置文件:
      1package cn.com.cinda.rtx.common;
      2
      3import java.io.BufferedReader;
      4import java.io.FileReader;
      5import java.io.IOException;
      6import java.util.HashMap;
      7import java.util.Properties;
      8import java.util.*;
      9import java.io.*;
     10
     11
     12public class IniReader {
     13    protected LinkedHashMap sections; //使用
     14
     15    public IniReader() {
     16        super();
     17        sections = new LinkedHashMap();
     18    }

     19
     20    public LinkedHashMap getSections() {
     21        return sections;
     22    }

     23
     24    public LinkedHashMap getSection(String sectionName) {
     25        if (sections != null{
     26            return (LinkedHashMap) sections.get(sectionName);
     27        }
     else {
     28            return null;
     29        }

     30    }

     31
     32    public String get(String sectionName, String key) {
     33        Map section1 = (Map) sections.get(sectionName);
     34        if (section1 == null{
     35            return "";
     36        }

     37        return (String) section1.get(key);
     38    }

     39
     40
     41    public void load(String fileName) throws FileNotFoundException {
     42        InputStream is = null;
     43        try {
     44            is = new FileInputStream(fileName);
     45            load(is);
     46        }
     catch (IOException e) {
     47            e.printStackTrace();
     48        }
     finally {
     49            if (is != null{
     50                try {
     51                    is.close();
     52                }
     catch (IOException e1) {}
     53            }

     54        }

     55    }

     56
     57    public void load(InputStream is) throws IOException {
     58        BufferedReader reader = new BufferedReader(new InputStreamReader(is));
     59        String line = null;
     60        String lastSectionName = null;
     61        while ((line = reader.readLine()) != null{
     62            line = line.trim();
     63            if (line.startsWith("#")) {
     64                continue;
     65            }

     66            if (line.startsWith("["&& line.endsWith("]")) {
     67                lastSectionName = line.trim().substring(1, line.length() - 1);
     68                sections.put(lastSectionName, new LinkedHashMap()); //創建一個section
     69            }
     else if (line.length() == 0{
     70                continue;
     71            }
     else {
     72                if (lastSectionName != null{
     73                    Map section = (Map) sections.get(lastSectionName);
     74                    int index = line.indexOf('=');
     75                    String key = index > 0 ? line.substring(0, index) : line; //如果沒有等號,直接做key和value
     76                    String value = index > 0 ? line.substring(index + 1) : line;
     77                    section.put(key, value);
     78                }

     79            }

     80        }

     81    }

     82
     83    public static void main(String[] args) {
     84        IniReader iniReader = new IniReader();
     85        try {
     86          FileInputStream fileInputStream = new FileInputStream("/etc/portalconf/jmsconfig.property");
     87            iniReader.load(fileInputStream);
     88            Map sections = iniReader.getSection("serverconf");
     89            java.util.Iterator it = sections.keySet().iterator();
     90            while (it.hasNext()) {
     91                String key = (String) it.next();
     92                System.out.println(key + "=" + sections.get(key));
     93            }

     94
     95        }
     catch (IOException e) {
     96            e.printStackTrace();
     97        }

     98    }

     99}

    100
    101
    102
    posted on 2007-06-26 14:34 冰封的愛 閱讀(1689) 評論(0)  編輯  收藏 所屬分類: 技術
    <2025年5月>
    27282930123
    45678910
    11121314151617
    18192021222324
    25262728293031
    1234567

    常用鏈接

    留言簿(3)

    隨筆檔案

    文章分類

    文章檔案

    相冊

    搜索

    •  

    最新評論

    閱讀排行榜

    評論排行榜

    主站蜘蛛池模板: 免费无遮挡无遮羞在线看| 久久aⅴ免费观看| 亚洲AV无一区二区三区久久| 国产真人无遮挡作爱免费视频| 免费一级毛片在线播放视频免费观看永久| 黑人大战亚洲人精品一区| 永久在线观看www免费视频| 国产亚洲av片在线观看播放| 国产va免费精品| 国产亚洲精品拍拍拍拍拍| 久久w5ww成w人免费| 亚洲综合无码一区二区三区| 国产成人在线观看免费网站| 日韩在线不卡免费视频一区| 久久亚洲精品国产精品| 国产免费观看a大片的网站| 视频一区二区三区免费观看| 亚洲精品免费观看| 999任你躁在线精品免费不卡| 色噜噜的亚洲男人的天堂| 久久噜噜噜久久亚洲va久| xx视频在线永久免费观看| 精品国产日韩久久亚洲| 亚洲成AV人在线观看天堂无码| 免费鲁丝片一级观看| 最近中文字幕免费完整| 农村寡妇一级毛片免费看视频| 亚洲人成电影网站| 亚洲国产成人久久综合碰| 手机在线毛片免费播放| 精品熟女少妇av免费久久| 人妻18毛片a级毛片免费看| 亚洲欧美国产欧美色欲| 久久精品国产精品亚洲人人| 最近2019中文字幕免费看最新| 免费观看在线禁片| 亚洲av无码久久忘忧草| 免费一级做a爰片久久毛片潮喷| 久久久久免费视频| 日韩亚洲人成在线综合| 亚洲一区中文字幕在线电影网|