Java System.getProperty method is very useful to find out the operating system information.

Java System.getProperty方法对于查找操作系统信息非常有用。

Java System.getProperty (Java System.getProperty)

We can use System.getProperty() method to find out the Operating System information, user home directory, Java runtime version, path separator, line separator, user working directory, Java home, Java classpath, and various other useful information.

我们可以使用System.getProperty()方法来查找操作系统信息,用户主目录,Java运行时版本,路径分隔符,行分隔符,用户工作目录,Java主目录,Java类路径以及各种其他有用的信息。

Java System getProperty示例 (Java System getProperty Example)

Java System class getProperties() method returns the Set of keys for the properties and here we will use it to list out all the system properties.

Java System类的 getProperties()方法返回属性的键集 ,在这里我们将使用它列出所有系统属性。

package com.journaldev.util;import java.util.Properties;
import java.util.Set;public class JavaSystemGetProperty {public static void main(String[] args) {Properties prop = System.getProperties();Set<Object> keySet = prop.keySet();for (Object obj : keySet) {System.out.println("System Property: {" + obj.toString() + "," + System.getProperty(obj.toString()) + "}");}}}

The output of the above System getProperty example program is;

上面的System getProperty示例程序的输出是;

System Property: {java.runtime.name,Java(TM) SE Runtime Environment}
System Property: {sun.boot.library.path,/Library/Java/JavaVirtualMachines/jdk1.8.0_131.jdk/Contents/Home/jre/lib}
System Property: {java.vm.version,25.131-b11}
System Property: {user.country.format,IN}
System Property: {gopherProxySet,false}
System Property: {java.vm.vendor,Oracle Corporation}
System Property: {java.vendor.url,https://java.oracle.com/}
System Property: {path.separator,:}
System Property: {java.vm.name,Java HotSpot(TM) 64-Bit Server VM}
System Property: {file.encoding.pkg,sun.io}
System Property: {user.country,US}
System Property: {sun.java.launcher,SUN_STANDARD}
System Property: {sun.os.patch.level,unknown}
System Property: {java.vm.specification.name,Java Virtual Machine Specification}
System Property: {user.dir,/Users/pankaj/Documents/eclipse-workspace/JavaExceptions}
System Property: {java.runtime.version,1.8.0_131-b11}
System Property: {java.awt.graphicsenv,sun.awt.CGraphicsEnvironment}
System Property: {java.endorsed.dirs,/Library/Java/JavaVirtualMachines/jdk1.8.0_131.jdk/Contents/Home/jre/lib/endorsed}
System Property: {os.arch,x86_64}
System Property: {java.io.tmpdir,/var/folders/1t/sx2jbcl534z88byy78_36ykr0000gn/T/}
System Property: {line.separator,
}
System Property: {java.vm.specification.vendor,Oracle Corporation}
System Property: {os.name,Mac OS X}
System Property: {sun.jnu.encoding,UTF-8}
System Property: {java.library.path,/Users/pankaj/Library/Java/Extensions:/Library/Java/Extensions:/Network/Library/Java/Extensions:/System/Library/Java/Extensions:/usr/lib/java:.}
System Property: {java.specification.name,Java Platform API Specification}
System Property: {java.class.version,52.0}
System Property: {sun.management.compiler,HotSpot 64-Bit Tiered Compilers}
System Property: {os.version,10.12.6}
System Property: {http.nonProxyHosts,local|*.local|169.254/16|*.169.254/16}
System Property: {user.home,/Users/pankaj}
System Property: {user.timezone,}
System Property: {java.awt.printerjob,sun.lwawt.macosx.CPrinterJob}
System Property: {file.encoding,UTF-8}
System Property: {java.specification.version,1.8}
System Property: {java.class.path,/Users/pankaj/Documents/eclipse-workspace/JavaExceptions/bin:/Users/pankaj/temp/commons-io-2.5.jar}
System Property: {user.name,pankaj}
System Property: {java.vm.specification.version,1.8}
System Property: {sun.java.command,com.journaldev.util.JavaSystemGetProperty}
System Property: {java.home,/Library/Java/JavaVirtualMachines/jdk1.8.0_131.jdk/Contents/Home/jre}
System Property: {sun.arch.data.model,64}
System Property: {user.language,en}
System Property: {java.specification.vendor,Oracle Corporation}
System Property: {awt.toolkit,sun.lwawt.macosx.LWCToolkit}
System Property: {java.vm.info,mixed mode}
System Property: {java.version,1.8.0_131}
System Property: {java.ext.dirs,/Users/pankaj/Library/Java/Extensions:/Library/Java/JavaVirtualMachines/jdk1.8.0_131.jdk/Contents/Home/jre/lib/ext:/Library/Java/Extensions:/Network/Library/Java/Extensions:/System/Library/Java/Extensions:/usr/lib/java}
System Property: {sun.boot.class.path,/Library/Java/JavaVirtualMachines/jdk1.8.0_131.jdk/Contents/Home/jre/lib/resources.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_131.jdk/Contents/Home/jre/lib/rt.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_131.jdk/Contents/Home/jre/lib/sunrsasign.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_131.jdk/Contents/Home/jre/lib/jsse.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_131.jdk/Contents/Home/jre/lib/jce.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_131.jdk/Contents/Home/jre/lib/charsets.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_131.jdk/Contents/Home/jre/lib/jfr.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_131.jdk/Contents/Home/jre/classes}
System Property: {java.vendor,Oracle Corporation}
System Property: {file.separator,/}
System Property: {java.vendor.url.bug,https://bugreport.sun.com/bugreport/}
System Property: {sun.io.unicode.encoding,UnicodeBig}
System Property: {sun.cpu.endian,little}
System Property: {socksNonProxyHosts,local|*.local|169.254/16|*.169.254/16}
System Property: {ftp.nonProxyHosts,local|*.local|169.254/16|*.169.254/16}
System Property: {sun.cpu.isalist,}

Some of the valuable information being printed above are;

上面印刷的一些有价值的信息是:

  1. The program is running on Mac OS, see output {os.name,Mac OS X}该程序在Mac OS上运行,请参见输出{os.name,Mac OS X}
  2. Java version is 1.8.0_131, see system property output {java.version,1.8.0_131}Java版本是1.8.0_131 ,请参见系统属性输出{java.version,1.8.0_131}
  3. User name is pankaj, as seen in output {user.name,pankaj}用户名是pankaj,如输出{user.name,pankaj}
  4. Path separator is colon (:), see output {path.separator,:}路径分隔符是冒号(:),请参见输出{path.separator,:}
  5. It’s a 64-bit OS, see output {os.arch,x86_64}这是一个64位操作系统,请参见输出{os.arch,x86_64}

There are many more useful information printed too, you should check them out.

还有很多其他有用的信息,您应该检查一下。

We should use this System information where we need to make sure our program is platform independent, for example creating the file path we should use file.separator property and to read PATH information we should use path.separator variable. That’s all about System.getProperty in java.

我们应该在需要确保程序独立于平台的地方使用此系统信息,例如,创建文件路径时应使用file.separator属性,并在读取PATH信息时应使用path.separator变量。 这就是java中的System.getProperty。

翻译自: https://www.journaldev.com/904/java-system-getproperty

Java System.getProperty()相关推荐

  1. Java System.arraycopy()方法示例

    Java System.arraycopy() is a native static method to copy elements from the source array to the dest ...

  2. Current在Java里面_在C#中相当于Java System.currentTimeMillis()

    替代: private static readonly DateTime Jan1st1970 = new DateTime (1970, 1, 1, 0, 0, 0, DateTimeKind.Ut ...

  3. lineseparator_首选System.lineSeparator()以用Java编写系统相关的行分隔符字符串

    lineseparator JDK 7在java.lang.System类上引入了一个名为lineSeparator()的新方法. 该方法不期待任何参数,并返回一个String ,它表示"取 ...

  4. 首选System.lineSeparator()以用Java编写系统相关的行分隔符字符串

    JDK 7在java.lang.System类上引入了一个名为lineSeparator()的新方法. 该方法不期待任何参数,并返回一个String ,它表示"取决于系统的行分隔符字符串.& ...

  5. Java中的System.exit()

    The System.exit() method terminates the Java virtual machine. This method takes an argument, which i ...

  6. 您需要了解的所有有关System.gc()的信息

    在本文中,我们试图回答有关System.gc()API调用的最常见问题. 我们希望它会有所帮助. 什么是System.gc()? System.gc()是用Java,Android,C#和其他流行语言 ...

  7. java 双等号(==) 与equals方法的介绍和区别

    java 双等号(==) 与equals方法的介绍和区别 1.基本数据类型与equals方法 == 用于比较基本数据类型时,比较的是值 ==用于比较引用数据类型时,比较的是地址 equals方法在Ob ...

  8. java 双等号(==) 与equals方法的使用区别

    java 双等号(==) 与equals方法的区别 == 用于比较基本数据类型时,比较的是值 ==用于比较引用数据类型时,比较的是地址 equals方法在Object类中比较的也是地址,因为在低层也是 ...

  9. Java列表add()和addAll()方法

    1. Java清单add() (1. Java List add()) This method is used to add elements to the list. There are two m ...

最新文章

  1. Hadoop实战(6)_搭建Apache Hadoop的Eclipse开发环境
  2. python之初体验(一)
  3. Adam是RmsProp和momentum算法的结合(列表比较)
  4. bootstrape常用标签_bootstrap_03_常用标签
  5. zabbix实现mysql数据库的监控
  6. NET问答: 如何从 string 中挖出所有的 number ?
  7. 冠军方案解读,ICPR 2020 大规模商品图像识别挑战赛
  8. linux开机自启服务命令,linux开机自启服务命令
  9. “天天快报”涉黄被下架?官方回应:不是我 是山寨版APP
  10. 《Installing the XDK and the dev kit OS》
  11. Say“No”,你学会了吗?
  12. C++ 从入门到入土(English Version)Section 6: Pointers and Call by Reference
  13. 权重的计算(熵权法)
  14. postman电脑版无法安装_Postman系列一:Postman安装及使用过程中遇到的问题
  15. 获得百词斩实体书的单词次序(咸鱼的编程初体验!)
  16. ARM9开发板实验笔记(1)
  17. [心得]如何系统自学经济学
  18. 如何写一篇数据分析报告3 - 分析背景是什么
  19. 使用 rimraf 快速删除 node_modules
  20. Matlab中结构体struct创建和使用

热门文章

  1. [转载] python删除dataframe行和列
  2. [置顶] Responder一点也不神秘————iOS用户响应者链完全剖析
  3. Java学习目录(持续更新中)
  4. cocos creator android之微信开放平台修改签名 baseResp.errCode=-6
  5. python 错误信息是:sudo :apt-get:command not found
  6. RabbitMQ消息队列入门篇(环境配置+Java实例+基础概念)
  7. windows下的文件遍历(使用CFindFile)
  8. 数据结构上机实践第八周项目4-字符串加密
  9. 数据结构上机实践第四周项目5 - 猴子选大王
  10. Python for和if的连写