加载属性文件以获取键值对

时间:2011-11-23 19:33:17

标签: java properties

PasswordBlurb7=\u4E0D\u53EF\u4F7F\u7528\u91CD\u8907\u5B57\u5143\uFF08\u4F8B\u5982 aaa64135\u3001111bcxjk\uFF09

我的一个属性文件包含上面的key = value对。所以当我尝试加载这个键时。我没有得到价值。我明白了????????在值

  Properties prop = new Properties();
  InputStream in = application.getResourceAsStream("WEB-INF/classes/content/"+line);
String value;
prop.load(in); 
for(Object str: prop.keySet()) {
            value = prop.getProperty((String) str);
            hashMap.put((String)str, value);

}

所以在我得到的价值中 -

??????????? aaa64135?111bcxjk? 

我输出的是这样的 -

<html>
<head>
</head>
<body>
<table border='2'>
<tr>
<th>Key</th>
<th>Values</th>
</tr>
<%
                        for (Entry<String, String> entry : hashMap.entrySet()) {
                                        String key = entry.getKey();
                                        String value = entry.getValue();
%>
<tr><td>
<% out.println(key); %>
</td>
<td>
<% out.println(value);  %>
</td></tr>
<%                                                      }
                        //out.println(hashMap);
                        } catch (FileNotFoundException e1) {
                                    e1.printStackTrace();
                        }
                        catch (IOException e) {
                                    e.printStackTrace();
                        } finally {

                        }

%>
</table>
</body>
</html>

我的代码有什么问题..

1 个答案:

答案 0 :(得分:2)

该属性是一个包含unicode转义字符的字符串。您看到?????...的原因很可能是您使用的输出设备不处理unicode,或者它使用的字体不包含这些亚洲符号:

\u4E0D\u53EF\u4F7F\u7528\u91CD\u8907\u5B57\u5143\uFF08\u4F8B\u5982 aaa64135\u3001111bcxjk\uFF09 

不可使用重複兇元(例如aaa64135、111bcxjk)