import java.util.Enumeration;
2.import java.util.HashMap;
3.import java.util.Map;
4.import java.util.Properties;
5.
6.import org.junit.Test;
7.
8.public class TestProperties {
9.
10. /**获取所有系统属性*/
11. @Test
12. public void getALLSystemProperties(){
13. Map<Object, Object> map = new HashMap<Object, Object>();
14.
15. Properties properties = System.getProperties();
16. Enumeration<Object> keys = properties.keys();
17. while (keys.hasMoreElements()) {
18. Object o = keys.nextElement();
19. map.put(o, properties.get(o));
20. }
21.
22. for(Map.Entry<Object, Object> obj : map.entrySet()){
23. System.out.println(obj.getKey()+"-----"+obj.getValue());
24. }
25. }
26.
27. /**获取具体的系统属性*/
28. @Test
29. public void getSystemProperties(){
30. Properties props=System.getProperties(); //系统属性
31. System.out.println("Java的运行环境版本:"+props.getProperty("java.version"));
32. System.out.println("Java的运行环境供应商:"+props.getProperty("java.vendor"));
33. System.out.println("Java供应商的URL:"+props.getProperty("java.vendor.url"));
34. System.out.println("Java的安装路径:"+props.getProperty("java.home"));
35. System.out.println("Java的虚拟机规范版本:"+props.getProperty("java.vm.specification.version"));
36. System.out.println("Java的虚拟机规范供应商:"+props.getProperty("java.vm.specification.vendor"));
37. System.out.println("Java的虚拟机规范名称:"+props.getProperty("java.vm.specification.name"));
38. System.out.println("Java的虚拟机实现版本:"+props.getProperty("java.vm.version"));
39. System.out.println("Java的虚拟机实现供应商:"+props.getProperty("java.vm.vendor"));
40. System.out.println("Java的虚拟机实现名称:"+props.getProperty("java.vm.name"));
41. System.out.println("Java运行时环境规范版本:"+props.getProperty("java.specification.version"));
42. System.out.println("Java运行时环境规范供应商:"+props.getProperty("java.specification.vender"));
43. System.out.println("Java运行时环境规范名称:"+props.getProperty("java.specification.name"));
44. System.out.println("Java的类格式版本号:"+props.getProperty("java.class.version"));
45. System.out.println("Java的类路径:"+props.getProperty("java.class.path"));
46. System.out.println("加载库时搜索的路径列表:"+props.getProperty("java.library.path"));
47. System.out.println("默认的临时文件路径:"+props.getProperty("java.io.tmpdir"));
48. System.out.println("一个或多个扩展目录的路径:"+props.getProperty("java.ext.dirs"));
49. System.out.println("操作系统的名称:"+props.getProperty("os.name"));
50. System.out.println("操作系统的构架:"+props.getProperty("os.arch"));
51. System.out.println("操作系统的版本:"+props.getProperty("os.version"));
52. System.out.println("文件分隔符:"+props.getProperty("file.separator")); //在 unix 系统中是"/"
53. System.out.println("路径分隔符:"+props.getProperty("path.separator")); //在 unix 系统中是":"
54. System.out.println("行分隔符:"+props.getProperty("line.separator")); //在 unix 系统中是"/n"
55. System.out.println("用户的账户名称:"+props.getProperty("user.name"));
56. System.out.println("用户的主目录:"+props.getProperty("user.home"));
57. System.out.println("用户的当前工作目录:"+props.getProperty("user.dir"));
58. }
59.}
System.getProperties(); //系统属性
猜你喜欢
转载自weitao1026.iteye.com/blog/2266118
今日推荐
周排行