JAVA系统属性之user home

我们可以通过System.getProperty("user.home")读取JAVA系统的user.home属性的值。
System.getProperty("user.home") 方法先去读取注册表中 HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell 
Folders 下的 Desktop 键值做为 user.dir ,再取它的上一级目录做为 user.home
打开注册表编辑器,定位到上面的键值,你可以发现 Desktop 的值是 %USERPROFILE%\桌面 这种形式。
%USERPROFILE% 对应 C:\Documents and Settings\%用户名% 。对于 Administrator 用户, 这里取得的Desktop自然是 C:\Documents and Settings\Administrator\桌面 . 那么 user.home 就应该是 C:\Documents and Settings\Administrator
示例1
public class PrintHome{
public static void main(String[] args) {
System.out.println(System.getProperty("user.home") );
}
}
有些电脑的注册表中的 Desktop可能变为 %USERPROFILE%\桌面 \这种形式。这时我们得到的 user.home可能会变成 C:\Documents and Settings\Administrator\桌面,这时需要手动修改 Desktop%USERPROFILE%\桌面这种形式,

再分享一下我老师大神的人工智能教程吧。零基础!通俗易懂!风趣幽默!还带黄段子!希望你也加入到我们人工智能的队伍中来!http://www.captainbed.net

猜你喜欢

转载自www.cnblogs.com/siwnchh/p/10464310.html