user.dir 是何方神圣。
据说 System.getProperty("user.dir");
可以获取我们计算机的系统信息。
那么 user.dir
的参数又该怎么传,ta 又可以获得哪些信息?
话不多说,追溯原因。好在文档注释写的非常详细。
/*** Determines the current system properties.* <p>* First, if there is a security manager, its* <code>checkPropertiesAccess</code> method is called with no* arguments. This may result in a security exception.* <p>* The current set of system properties for use by the* {@link #getProperty(String)} method is returned as a* <code>Properties</code> object. If there is no current set of* system properties, a set of system properties is first created and* initialized. This set of system properties always includes values* for the following keys:* <table summary="Shows property keys and associated values">* <tr><th>Key</th>* <th>Description of Associated Value</th></tr>* <tr><td><code>java.version</code></td>* <td>Java Runtime Environment version</td></tr>* <tr><td><code>java.vendor</code></td>* <td>Java Runtime Environment vendor</td></tr>* <tr><td><code>java.vendor.url</code></td>* <td>Java vendor URL</td></tr>* <tr><td><code>java.home</code></td>* <td>Java installation directory</td></tr>* <tr><td><code>java.vm.specification.version</code></td>* <td>Java Virtual Machine specification version</td></tr>* <tr><td><code>java.vm.specification.vendor</code></td>* <td>Java Virtual Machine specification vendor</td></tr>* <tr><td><code>java.vm.specification.name</code></td>* <td>Java Virtual Machine specification name</td></tr>* <tr><td><code>java.vm.version</code></td>* <td>Java Virtual Machine implementation version</td></tr>* <tr><td><code>java.vm.vendor</code></td>* <td>Java Virtual Machine implementation vendor</td></tr>* <tr><td><code>java.vm.name</code></td>* <td>Java Virtual Machine implementation name</td></tr>* <tr><td><code>java.specification.version</code></td>* <td>Java Runtime Environment specification version</td></tr>* <tr><td><code>java.specification.vendor</code></td>* <td>Java Runtime Environment specification vendor</td></tr>* <tr><td><code>java.specification.name</code></td>* <td>Java Runtime Environment specification name</td></tr>* <tr><td><code>java.class.version</code></td>* <td>Java class format version number</td></tr>* <tr><td><code>java.class.path</code></td>* <td>Java class path</td></tr>* <tr><td><code>java.library.path</code></td>* <td>List of paths to search when loading libraries</td></tr>* <tr><td><code>java.io.tmpdir</code></td>* <td>Default temp file path</td></tr>* <tr><td><code>java.compiler</code></td>* <td>Name of JIT compiler to use</td></tr>* <tr><td><code>java.ext.dirs</code></td>* <td>Path of extension directory or directories* <b>Deprecated.</b> <i>This property, and the mechanism* which implements it, may be removed in a future* release.</i> </td></tr>* <tr><td><code>os.name</code></td>* <td>Operating system name</td></tr>* <tr><td><code>os.arch</code></td>* <td>Operating system architecture</td></tr>* <tr><td><code>os.version</code></td>* <td>Operating system version</td></tr>* <tr><td><code>file.separator</code></td>* <td>File separator ("/" on UNIX)</td></tr>* <tr><td><code>path.separator</code></td>* <td>Path separator (":" on UNIX)</td></tr>* <tr><td><code>line.separator</code></td>* <td>Line separator ("\n" on UNIX)</td></tr>* <tr><td><code>user.name</code></td>* <td>User's account name</td></tr>* <tr><td><code>user.home</code></td>* <td>User's home directory</td></tr>* <tr><td><code>user.dir</code></td>* <td>User's current working directory</td></tr>* </table>* <p>* Multiple paths in a system property value are separated by the path* separator character of the platform.* <p>* Note that even if the security manager does not permit the* <code>getProperties</code> operation, it may choose to permit the* {@link #getProperty(String)} operation.** @return the system properties* @exception SecurityException if a security manager exists and its* <code>checkPropertiesAccess</code> method doesn't allow access* to the system properties.* @see #setProperties* @see java.lang.SecurityException* @see java.lang.SecurityManager#checkPropertiesAccess()* @see java.util.Properties*/public static Properties getProperties() {SecurityManager sm = getSecurityManager();if (sm != null) {sm.checkPropertiesAccess();}return props;}
Key | Description of Associated Value |
---|---|
java.version | Java Runtime Environment version |
java.vendor | Java Runtime Environment vendor |
java.vendor.url | Java vendor URL |
java.home | Java installation directory |
java.vm.specification.version | Java Virtual Machine specification version |
java.vm.specification.vendor | Java Virtual Machine specification vendor |
java.vm.specification.name | Java Virtual Machine specification name |
java.vm.version | Java Virtual Machine implementation version |
java.vm.vendor | Java Virtual Machine implementation vendor |
java.vm.name | Java Virtual Machine implementation name |
java.specification.version | Java Runtime Environment specification version |
java.specification.vendor | Java Runtime Environment specification vendor |
java.specification.name | Java Runtime Environment specification name |
java.class.version | Java class format version number |
java.class.path | Java class path |
java.library.path | List of paths to search when loading libraries |
java.io.tmpdir | Default temp file path |
java.compiler | Name of JIT compiler to use |
java.ext.dirs | Path of extension directory or directories Deprecated. This property, and the mechanism which implements it, may be removed in a future release. |
os.name | Operating system name |
os.arch | Operating system architecture |
os.version | Operating system version |
file.separator | File separator ("/" on UNIX) |
path.separator | Path separator (":" on UNIX) |
line.separator | Line separator ("\n" on UNIX) |
user.name | User's account name |
user.home | User's home directory |
user.dir | User's current working directory |
package com.geek;public class HelloWorld {public static void main(String[] args) {System.out.println(System.getProperty("java.version"));// Java Runtime Environment version// 11.0.6System.out.println(System.getProperty("java.vendor"));// Java Runtime Environment vendor// JetBrains s.r.oSystem.out.println(System.getProperty("java.vendor.url"));// Java vendor URL// https://www.jetbrains.com/System.out.println(System.getProperty("java.home"));// Java installation directory// /home/geek/geek/tools_my/idea-IU-193.7288.26/jbrSystem.out.println(System.getProperty("java.vm.specification.version"));// Java Virtual Machine specification version// 11System.out.println(System.getProperty("java.vm.specification.vendor"));// Java Virtual Machine specification vendor// Oracle CorporationSystem.out.println(System.getProperty("java.vm.specification.name"));// Java Virtual Machine specification name// Java Virtual Machine SpecificationSystem.out.println(System.getProperty("java.vm.version"));// Java Virtual Machine implementation version// 11.0.6+8-b520.66System.out.println(System.getProperty("java.vm.vendor"));// Java Virtual Machine implementation vendor// JetBrains s.r.oSystem.out.println(System.getProperty("java.vm.name"));// Java Virtual Machine implementation name// OpenJDK 64-Bit Server VMSystem.out.println(System.getProperty("java.specification.version"));// Java Runtime Environment specification version// 11System.out.println(System.getProperty("java.specification.vendor"));// Java Runtime Environment specification vendor// Oracle CorporationSystem.out.println(System.getProperty("java.specification.name"));// Java Runtime Environment System.out.println();specification name// Java Platform API SpecificationSystem.out.println(System.getProperty("java.class.version"));// Java class format version number// 55.0System.out.println(System.getProperty("java.class.path"));// Java class path// /root/IdeaProjects/untitled/out/production/HelloWorld:/home/geek/geek/tools_my/idea-IU-193.7288.26/lib/idea_rt.jarSystem.out.println(System.getProperty("java.library.path"));// List of paths to search when loading libraries// /usr/java/packages/lib:/usr/lib64:/lib64:/lib:/usr/libSystem.out.println(System.getProperty("java.io.tmpdir"));// Default temp file path// /tmpSystem.out.println(System.getProperty("java.compiler"));// Name of JIT compiler to use// nullSystem.out.println(System.getProperty("java.ext.dirs"));// Path of extension directory or directories Deprecated. This property, and the mechanism which implements it, may be removed in a future release.// nullSystem.out.println(System.getProperty("os.name"));// Operating system name// LinuxSystem.out.println(System.getProperty("os.arch"));// Operating system architecture// amd64System.out.println(System.getProperty("os.version"));// Operating system version// 5.4.0-31-genericSystem.out.println(System.getProperty("file.separator"));// File separator ("/" on UNIX)// /System.out.println(System.getProperty("path.separator"));// Path separator (":" on UNIX)// :System.out.println(System.getProperty("line.separator"));// Line separator ("\n" on UNIX)//System.out.println(System.getProperty("user.name"));// User's account name// rootSystem.out.println(System.getProperty("user.home"));// User's home directory// /rootSystem.out.println(System.getProperty("user.dir"));// User's current working directory// /root/IdeaProjects/untitled}}
package com.geek;public class JavaTest {public static void main(String[] args) {System.out.println(System.getProperty("java.version"));// Java Runtime Environment version// 1.8.0_241System.out.println(System.getProperty("java.vendor"));// Java Runtime Environment vendor// Oracle CorporationSystem.out.println(System.getProperty("java.vendor.url"));// Java vendor URL// http://java.oracle.com/System.out.println(System.getProperty("java.home"));// Java installation directory// G:\lyfGeek\ProgramFiles\Java\jdk1.8.0_241\jreSystem.out.println(System.getProperty("java.vm.specification.version"));// Java Virtual Machine specification version// 1.8System.out.println(System.getProperty("java.vm.specification.vendor"));// Java Virtual Machine specification vendor// Oracle CorporationSystem.out.println(System.getProperty("java.vm.specification.name"));// Java Virtual Machine specification name// Java Virtual Machine SpecificationSystem.out.println(System.getProperty("java.vm.version"));// Java Virtual Machine implementation version// 25.241-b07System.out.println(System.getProperty("java.vm.vendor"));// Java Virtual Machine implementation vendor// Oracle CorporationSystem.out.println(System.getProperty("java.vm.name"));// Java Virtual Machine implementation name// Java HotSpot(TM) 64-Bit Server VMSystem.out.println(System.getProperty("java.specification.version"));// Java Runtime Environment specification version// 1.8System.out.println(System.getProperty("java.specification.vendor"));// Java Runtime Environment specification vendor// Oracle CorporationSystem.out.println(System.getProperty("java.specification.name"));// Java Runtime Environment System.out.println();specification name// Java Platform API SpecificationSystem.out.println(System.getProperty("java.class.version"));// Java class format version number// 52.0System.out.println(System.getProperty("java.class.path"));// Java class path// G:\lyfGeek\ProgramFiles\Java\jdk1.8.0_241\jre\lib\charsets.jar;G:\lyfGeek\ProgramFiles\Java\jdk1.8.0_241\jre\lib\deploy.jar;G:\lyfGeek\ProgramFiles\Java\jdk1.8.0_241\jre\lib\ext\access-bridge-64.jar;G:\lyfGeek\ProgramFiles\Java\jdk1.8.0_241\jre\lib\ext\cldrdata.jar;G:\lyfGeek\ProgramFiles\Java\jdk1.8.0_241\jre\lib\ext\dnsns.jar;G:\lyfGeek\ProgramFiles\Java\jdk1.8.0_241\jre\lib\ext\jaccess.jar;G:\lyfGeek\ProgramFiles\Java\jdk1.8.0_241\jre\lib\ext\jfxrt.jar;G:\lyfGeek\ProgramFiles\Java\jdk1.8.0_241\jre\lib\ext\localedata.jar;G:\lyfGeek\ProgramFiles\Java\jdk1.8.0_241\jre\lib\ext\nashorn.jar;G:\lyfGeek\ProgramFiles\Java\jdk1.8.0_241\jre\lib\ext\sunec.jar;G:\lyfGeek\ProgramFiles\Java\jdk1.8.0_241\jre\lib\ext\sunjce_provider.jar;G:\lyfGeek\ProgramFiles\Java\jdk1.8.0_241\jre\lib\ext\sunmscapi.jar;G:\lyfGeek\ProgramFiles\Java\jdk1.8.0_241\jre\lib\ext\sunpkcs11.jar;G:\lyfGeek\ProgramFiles\Java\jdk1.8.0_241\jre\lib\ext\zipfs.jar;G:\lyfGeek\ProgramFiles\Java\jdk1.8.0_241\jre\lib\javaws.jar;G:\lyfGeek\ProgramFiles\Java\jdk1.8.0_241\jre\lib\jce.jar;G:\lyfGeek\ProgramFiles\Java\jdk1.8.0_241\jre\lib\jfr.jar;G:\lyfGeek\ProgramFiles\Java\jdk1.8.0_241\jre\lib\jfxswt.jar;G:\lyfGeek\ProgramFiles\Java\jdk1.8.0_241\jre\lib\jsse.jar;G:\lyfGeek\ProgramFiles\Java\jdk1.8.0_241\jre\lib\management-agent.jar;G:\lyfGeek\ProgramFiles\Java\jdk1.8.0_241\jre\lib\plugin.jar;G:\lyfGeek\ProgramFiles\Java\jdk1.8.0_241\jre\lib\resources.jar;G:\lyfGeek\ProgramFiles\Java\jdk1.8.0_241\jre\lib\rt.jar;G:\lyfGeek\IdeaProjects\mybatis-geek\mybatis-05-multi\target\test-classes;G:\lyfGeek\IdeaProjects\mybatis-geek\mybatis-05-multi\target\classes;G:\lyfGeek\maven_repository\mysql\mysql-connector-java\5.1.47\mysql-connector-java-5.1.47.jar;G:\lyfGeek\maven_repository\org\mybatis\mybatis\3.5.3\mybatis-3.5.3.jar;G:\lyfGeek\maven_repository\junit\junit\4.12\junit-4.12.jar;G:\lyfGeek\maven_repository\org\hamcrest\hamcrest-core\1.3\hamcrest-core-1.3.jar;G:\lyfGeek\maven_repository\org\projectlombok\lombok\1.18.12\lombok-1.18.12.jar;G:\lyfGeek\Program Files\JetBrains\IntelliJ IDEA 2018.3.6\lib\idea_rt.jar;C:\Users\geek\.IntelliJIdea2018.3\system\captureAgent\debugger-agent.jarSystem.out.println(System.getProperty("java.library.path"));// List of paths to search when loading libraries// G:\lyfGeek\ProgramFiles\Java\jdk1.8.0_241\bin;C:\Windows\Sun\Java\bin;C:\Windows\system32;C:\Windows;C:\Program Files (x86)\Common Files\Oracle\Java\javapath;F:\Program Files (x86)\Python37-32\Scripts\;F:\Program Files (x86)\Python37-32\;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Windows\System32\OpenSSH\;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Program Files\NVIDIA Corporation\NVIDIA NvDLISR;g:\lyfgeek\ProgramFiles\Git\cmd;C:\Users\geek\AppData\Local\Microsoft\WindowsApps;;g:\lyfGeek\Program Files\JetBrains\IntelliJ IDEA 2018.3.6\bin;;g:\Program Files\JetBrains\PyCharm 2018.3.7\bin;;g:\Program Files\JetBrains\WebStorm 2020.1.1\bin;;.System.out.println(System.getProperty("java.io.tmpdir"));// Default temp file path// C:\Users\geek\AppData\Local\Temp\System.out.println(System.getProperty("java.compiler"));// Name of JIT compiler to use// nullSystem.out.println(System.getProperty("java.ext.dirs"));// Path of extension directory or directories Deprecated. This property, and the mechanism which implements it, may be removed in a future release.//System.out.println(System.getProperty("os.name"));// Operating system name// Windows 10System.out.println(System.getProperty("os.arch"));// Operating system architecture// amd64System.out.println(System.getProperty("os.version"));// Operating system version// 10.0System.out.println(System.getProperty("file.separator"));// File separator ("/" on UNIX)// \System.out.println(System.getProperty("path.separator"));// Path separator (":" on UNIX)// ;System.out.println(System.getProperty("line.separator"));// Line separator ("\n" on UNIX)//System.out.println(System.getProperty("user.name"));// User's account name// geekSystem.out.println(System.getProperty("user.home"));// User's home directory// C:\Users\geekSystem.out.println(System.getProperty("user.dir"));// User's current working directory// G:\lyfGeek\IdeaProjects\mybatis-geek}}
package com.geek;public class JavaTest {public static void main(String[] args) {System.out.println(System.getProperty("java.version"));// Java Runtime Environment version// 11.0.6System.out.println(System.getProperty("java.vendor"));// Java Runtime Environment vendor// JetBrains s.r.oSystem.out.println(System.getProperty("java.vendor.url"));// Java vendor URL// https://www.jetbrains.com/System.out.println(System.getProperty("java.home"));// Java installation directory// /home/geek/geek/tools_my/idea-IU-193.7288.26/jbrSystem.out.println(System.getProperty("java.vm.specification.version"));// Java Virtual Machine specification version// 11System.out.println(System.getProperty("java.vm.specification.vendor"));// Java Virtual Machine specification vendor// Oracle CorporationSystem.out.println(System.getProperty("java.vm.specification.name"));// Java Virtual Machine specification name// Java Virtual Machine SpecificationSystem.out.println(System.getProperty("java.vm.version"));// Java Virtual Machine implementation version// 11.0.6+8-b520.66System.out.println(System.getProperty("java.vm.vendor"));// Java Virtual Machine implementation vendor// JetBrains s.r.oSystem.out.println(System.getProperty("java.vm.name"));// Java Virtual Machine implementation name// OpenJDK 64-Bit Server VMSystem.out.println(System.getProperty("java.specification.version"));// Java Runtime Environment specification version// 11System.out.println(System.getProperty("java.specification.vendor"));// Java Runtime Environment specification vendor// Oracle CorporationSystem.out.println(System.getProperty("java.specification.name"));// Java Runtime Environment System.out.println();specification name// Java Platform API SpecificationSystem.out.println(System.getProperty("java.class.version"));// Java class format version number// 55.0System.out.println(System.getProperty("java.class.path"));// Java class path// /home/geek/IdeaProjects/untitled/out/production/untitled:/home/geek/geek/tools_my/idea-IU-193.7288.26/lib/idea_rt.jarSystem.out.println(System.getProperty("java.library.path"));// List of paths to search when loading libraries// /usr/java/packages/lib:/usr/lib64:/lib64:/lib:/usr/libSystem.out.println(System.getProperty("java.io.tmpdir"));// Default temp file path// /tmpSystem.out.println(System.getProperty("java.compiler"));// Name of JIT compiler to use// nullSystem.out.println(System.getProperty("java.ext.dirs"));// Path of extension directory or directories Deprecated. This property, and the mechanism which implements it, may be removed in a future release.// nullSystem.out.println(System.getProperty("os.name"));// Operating system name// LinuxSystem.out.println(System.getProperty("os.arch"));// Operating system architecture// amd64System.out.println(System.getProperty("os.version"));// Operating system version// 5.4.0-31-genericSystem.out.println(System.getProperty("file.separator"));// File separator ("/" on UNIX)// /System.out.println(System.getProperty("path.separator"));// Path separator (":" on UNIX)// :System.out.println(System.getProperty("line.separator"));// Line separator ("\n" on UNIX)//System.out.println(System.getProperty("user.name"));// User's account name// geekSystem.out.println(System.getProperty("user.home"));// User's home directory// /home/geekSystem.out.println(System.getProperty("user.dir"));// User's current working directory// /home/geek/IdeaProjects/untitled}}