一个例子
获取当前IDE打开的helloword工程路径:
String dir = System.getProperty("user.dir");
String java = System.getProperty("java.home");
String os = System.getProperty("os.name");
System.out.println(dir);
System.out.println(java);
System.out.println(os);
打印结果:
C:\workspace\study\project\helloworld
C:\Program Files\Java\jdk1.8.0_202\jre
Windows 10
更多系统属性
-
java.version
- Java version number java.vendor
- Java vendor specific string java.vendor.url
- Java vendor URL java.home
- Java installation directory java.class.version
- Java class version number java.class.path
- Java classpath 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 account name user.home
- User home directory user.dir
- User's current working directory