本文共 769 字,大约阅读时间需要 2 分钟。
我们可以通过 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 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://hqrdi.baihongyu.com/