Java如何获取用户主目录名称?
package org.nhooo.example.lang;
public class UserHomeExample {
public static void main(String[] args) {
//这是我们用来获取用户主目录的密钥
//在操作系统中
String userHome = "user.home";
//我们通过获取带有
//上面定义的键。
String path = System.getProperty(userHome);
//我们在这里打印您的回家路径
System.out.println("Your Home Path: " + path);
}
}在我的机器上,它打印如下内容:
Your Home Path: C:\Users\wsaryada
要么
Your Home Path: /Users/wsaryada