zhuguifei
2026-03-10 58402bd5e762361363a0f7d7907153c77dbb819f
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
package com.shlanbao.tzsc.utils.tools;
 
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStreamReader;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Hashtable;
import java.util.Map;
import java.util.ResourceBundle;
 
/**
 * 项目参数工具类
 * <li>@author Leejean
 * <li>@create 2014-6-24 下午04:38:11
 */
public class ConfigUtil {
 
    private static ResourceBundle bundle = null;
    
    public static void initBundle(String name) {
        bundle = java.util.ResourceBundle.getBundle(name);
    }
    /**
     * 通过键获取值
     * @param key
     * @return
     */
    public static final String get(String configName,String key) {
        initBundle(configName);
        return bundle.getString(key);
    }
    
    
    
    public static final Map<String,String> getParamsMap(String configName){
        initBundle(configName);
        Map<String,String> paramsMap=new HashMap<String, String>();
         Enumeration<String> enumeration=bundle.getKeys();
         while (enumeration.hasMoreElements()) {
            String key = (String) enumeration.nextElement();
            paramsMap.put(key, bundle.getString(key));
            System.out.println(key);
        }
        return paramsMap;
    }
    
    /**
     * @deprecated
     * 读取GD故障德中文对照关系
     * @return
     */
    public static Hashtable<String,String> readTxtFile(){
        String filePath = ConfigUtil.class.getClassLoader().getResource("GD_Compile.txt").getPath().toString();
        Hashtable<String,String> ht=new Hashtable<String,String>();
        try {  
            String encoding="UTF-8";  
            File file=new File(filePath);  
            if(file.isFile() && file.exists()){ //判断文件是否存在  
                InputStreamReader read = new InputStreamReader(  
                new FileInputStream(file),encoding);//考虑到编码格式  
                BufferedReader bufferedReader = new BufferedReader(read);  
                String lineTxt = null;
                while((lineTxt = bufferedReader.readLine()) != null){  
                    try{
                        ht.put(lineTxt.substring(0, lineTxt.indexOf("^")).trim(), lineTxt.substring(lineTxt.indexOf("^")+1,lineTxt.length()).trim());
                    }catch(Exception ex){
                        System.out.println("读取GD故障中英文转换错误");
                    }
                }  
                read.close();  
            }else{  
                System.out.println("读取GD故障中英文转换错误_找不到指定的文件");  
            }  
        } catch (Exception e) {  
            System.out.println("读取GD故障中英文转换错误_读取文件内容出错");  
            e.printStackTrace();  
        }  
        return ht;
      
    } 
}