JAVA系统属性之user home

时间:2019-03-03 11:07:57   收藏:0   阅读:1528
我们可以通过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

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!