Java System类相关属性和方法

原创 Laughing  2017-11-05 19:56  阅读 53 次 评论 0 条
  1. Map<String, String> envMap = System.getenv();//获取系统环境变量  
  2.         for (String nameString : envMap.keySet()) {  
  3.             System.out.println(nameString+"------"+envMap.get(nameString));  
  4.         }  
  5.         System.out.println(System.getenv("HOME"));  
  6.         Properties props = System.getProperties();//获取系统属性  
  7.         props.store(new FileOutputStream("prop.txt"), "System Properties");//存储系统属性  
  8.         System.out.println(System.getProperty("os.name"));//获取系统名称  
  9.         System.out.println(System.currentTimeMillis());//获取当前时间  


输出文件

prop.txt

  1. #System Properties  
  2. #Sun Nov 05 19:49:22 CST 2017  
  3. java.runtime.name=Java(TM) SE Runtime Environment  
  4. sun.boot.library.path=/Library/Java/JavaVirtualMachines/jdk1.8.0_151.jdk/Contents/Home/jre/lib  
  5. java.vm.version=25.151-b12  
  6. gopherProxySet=false  
  7. java.vm.vendor=Oracle Corporation  
  8. java.vendor.url=http\://java.oracle.com/  
  9. path.separator=\:  
  10. java.vm.name=Java HotSpot(TM) 64-Bit Server VM  
  11. file.encoding.pkg=sun.io  
  12. user.country=CN  
  13. sun.java.launcher=SUN_STANDARD  
  14. sun.os.patch.level=unknown  
  15. java.vm.specification.name=Java Virtual Machine Specification  
  16. user.dir=/Users/lisen/Git/JavaStudy/JavaStudy  
  17. java.runtime.version=1.8.0_151-b12  
  18. java.awt.graphicsenv=sun.awt.CGraphicsEnvironment  
  19. java.endorsed.dirs=/Library/Java/JavaVirtualMachines/jdk1.8.0_151.jdk/Contents/Home/jre/lib/endorsed  
  20. os.arch=x86_64  
  21. java.io.tmpdir=/var/folders/74/4j3x8x8n0jv0fzhjm8xhnnfc0000gn/T/  
  22. line.separator=\n  
  23. java.vm.specification.vendor=Oracle Corporation  
  24. os.name=Mac OS X  
  25. sun.jnu.encoding=UTF-8  
  26. java.library.path=/Users/lisen/Library/Java/Extensions\:/Library/Java/Extensions\:/Network/Library/Java/Extensions\:/System/Library/Java/Extensions\:/usr/lib/java\:.  
  27. java.specification.name=Java Platform API Specification  
  28. java.class.version=52.0  
  29. sun.management.compiler=HotSpot 64-Bit Tiered Compilers  
  30. os.version=10.13.2  
  31. user.home=/Users/lisen  
  32. user.timezone=Asia/Shanghai  
  33. java.awt.printerjob=sun.lwawt.macosx.CPrinterJob  
  34. file.encoding=UTF-8  
  35. java.specification.version=1.8  
  36. java.class.path=/Users/lisen/Git/JavaStudy/JavaStudy/bin  
  37. user.name=lisen  
  38. java.vm.specification.version=1.8  
  39. sun.java.command=NullStaticAccess  
  40. java.home=/Library/Java/JavaVirtualMachines/jdk1.8.0_151.jdk/Contents/Home/jre  
  41. sun.arch.data.model=64  
  42. user.language=zh  
  43. java.specification.vendor=Oracle Corporation  
  44. awt.toolkit=sun.lwawt.macosx.LWCToolkit  
  45. java.vm.info=mixed mode  
  46. java.version=1.8.0_151  
  47. java.ext.dirs=/Users/lisen/Library/Java/Extensions\:/Library/Java/JavaVirtualMachines/jdk1.8.0_151.jdk/Contents/Home/jre/lib/ext\:/Library/Java/Extensions\:/Network/Library/Java/Extensions\:/System/Library/Java/Extensions\:/usr/lib/java  
  48. sun.boot.class.path=/Library/Java/JavaVirtualMachines/jdk1.8.0_151.jdk/Contents/Home/jre/lib/resources.jar\:/Library/Java/JavaVirtualMachines/jdk1.8.0_151.jdk/Contents/Home/jre/lib/rt.jar\:/Library/Java/JavaVirtualMachines/jdk1.8.0_151.jdk/Contents/Home/jre/lib/sunrsasign.jar\:/Library/Java/JavaVirtualMachines/jdk1.8.0_151.jdk/Contents/Home/jre/lib/jsse.jar\:/Library/Java/JavaVirtualMachines/jdk1.8.0_151.jdk/Contents/Home/jre/lib/jce.jar\:/Library/Java/JavaVirtualMachines/jdk1.8.0_151.jdk/Contents/Home/jre/lib/charsets.jar\:/Library/Java/JavaVirtualMachines/jdk1.8.0_151.jdk/Contents/Home/jre/lib/jfr.jar\:/Library/Java/JavaVirtualMachines/jdk1.8.0_151.jdk/Contents/Home/jre/classes  
  49. java.vendor=Oracle Corporation  
  50. file.separator=/  
  51. java.vendor.url.bug=http\://bugreport.sun.com/bugreport/  
  52. sun.io.unicode.encoding=UnicodeBig  
  53. sun.cpu.endian=little  
  54. sun.cpu.isalist=  
本文地址:https://www.lisen.me/java-system-class-related-attributes-and-methods.html
版权声明:本文为原创文章,版权归 木子网 所有,欢迎分享本文,转载请保留出处!

发表评论


表情