打印System.getProperties的属性值

来源:互联网 发布:淘宝女装文案模板 编辑:程序博客网 时间:2024/06/05 19:43


import java.util.*;public class MyTest{    /**     * Create the panel.     */    public MyTest() {        java.util.Properties pp = System.getProperties();        java.util.Enumeration en = pp.propertyNames();        TreeMap<String, String> map = new TreeMap<String, String>(new Comparator<String>() {            /*             * int compare(Object o1, Object o2) 返回一个基本类型的整型,             * 返回负数表示:o1 小于o2,             * 返回0 表示:o1和o2相等,             * 返回正数表示:o1大于o2。             */            public int compare(String o1, String o2) {                //指定排序器按照升序排列 a-z                return o1.compareTo(o2);            }        });        while (en.hasMoreElements()) {            String elm = (String) en.nextElement();            map.put(elm, encodeHTML(pp.getProperty(elm)));        }        StringBuffer buffer = new StringBuffer();        buffer.append("<Table>");        int i = 0;        Set<Map.Entry<String, String>> entries = map.entrySet();        Iterator<Map.Entry<String, String>> it = entries.iterator();        while (it.hasNext()) {            String color = i % 2 == 1 ? "#ddd" : "";            buffer.append("<tr style='background-color:" + color + "'><td style='color:blue'>");            Map.Entry<String, String> next = it.next();            buffer.append(next.getKey());            buffer.append("</td><td>");            buffer.append(next.getValue());            buffer.append("</td></tr>");            i++;        }        buffer.append("</Table>");        System.out.println(buffer.toString());    }    public static String encodeHTML(String str) {        String retStr = "";        retStr = str.replaceAll(" ", " ");        retStr = str.replaceAll("<", "<");        retStr = str.replaceAll(">", ">");        retStr = str.replaceAll("\n", "<br/>");        retStr = str.replaceAll("\n\r", "<br>");        str.replaceAll("&", "&");        return retStr;    }    public static void main(String[] args) {        MyTest m = new MyTest();    }}


0 0
原创粉丝点击