/** * 取得系统属性,如果因为Java安全的限制而失败,则将错误打在<code>System.err</code>中,然后返回 <code>null</code>。 * * @param name 属性名 * @param quiet 安静模式,不将出错信息打在<code>System.err</code>中 * @return 属性值或<code>null</code> */ private static String getSystemProperty(String name, boolean quiet) { try { return System.getProperty(name); } catch (SecurityException e) { if (!quiet) { System.err.println( "Caught a SecurityException reading the system property '" + name + "'; the SystemUtil property value will default to null."); } return null; } }
public static void main(String[] args) { dumpSystemInfo(); Set<?> keys = System.getProperties().keySet(); @SuppressWarnings("unchecked") List<String> list = createArrayList((Set<String>) keys); Collections.sort(list); for (String key : list) { String value = System.getProperty(key); System.out.println(key + " = " + defaultIfNull(StringEscapeUtil.escapeJava(value), "[n/a]")); } }