Momy

<< Teamcenter for Simulation | 首 页 | napkin >> 【转载】好用的获取环境变量的java静态方法 - [ 技术 ] Tag: java 环境变量 获取 方法 版权声明 :转载时请以超链接形式标明文章原始出处和作者信息及 本声明 http://momy.blogbus.com/logs/16503246.html public static String getEnv(String envKey) { Properties prop = new Properties(); try { String OS = System.getProperty("os.name").toLowerCase(); Process p = null; //get system environment if (OS.indexOf("windows") > -1) { p = Runtime.getRuntime().exec("cmd /c set"); } BufferedReader br = new BufferedReader(new InputStreamReader(p .getInputStream())); String line; while ((line = br.readLine()) != null) { int i = line.indexOf("="); if (i > -1) { String key = line.substring(0, i); String value = line.substring(i + 1); prop.setProperty(key, value); } } return prop.getProperty(envKey); } catch (Exception e) { return null; } } 随机文章: 非正版Windows Media player 10升级至11后通过验证方法 2008-04-04 JTable Examples 2008-03-29 文件操作小技巧 2008-01-07 远程连接sqlserver2005的问题 (续) 2007-11-07 远程连接sqlserver2005的问题 2007-10-27 收藏到: Del.icio.us 引用地址: momy 发表于 16:37:19 2008-03-06 | 编辑 | 继续话题 | 转发 | 推荐 引用 下面Blog引用了该文: SAXReader用法(根据xml模板文件在指定路径下生成新的xml文件,部分内容更新) Blog: Momy 2008-03-30 20:20:54 发表评论

原始快照:web.archive.org