String userHome = System.getProperty("user.home");//用戶的主目錄System.out.println("userHome: "+userHome);
String userDir = System.getProperty("user.dir");//項目的當前工作目錄
System.out.println("userDir: "+userDir);
String userName = System.getProperty("user.name");//用戶的賬戶名稱
System.out.println("userName: "+userName);
String fileSeparator = System.getProperty("file.separator");//文件分隔符,或可直接用File.separator獲得
System.out.println("fileSeparator : "+fileSeparator);
String pathSeparator = System.getProperty("path.separator");//路徑分隔符
System.out.println("pathSeparator : "+ pathSeparator);
輸出結果:
userHome: C:\Users\wangyibo
userDir: D:\IdeaProject\test
userName: wangyibo
fileSeparator : \
pathSeparator : ;
Process finished with exit code 0
參考鏈接: https://blog.51cto.com/jtech/2151930
http://www.yayihouse.com/yayishuwu/chapter/1114
//輸出所有properties
Properties props = System.getProperties();
props.list(System.out);