博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
JAVA系统属性之user.home
阅读量:4043 次
发布时间:2019-05-24

本文共 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
示例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://hqrdi.baihongyu.com/

你可能感兴趣的文章
使用file查看可执行文件的平台性,x86 or arm ?
查看>>
qt5 everywhere 编译summary
查看>>
qt5 everywhere编译完成后,找不到qmake
查看>>
qt 创建异形窗体
查看>>
可重入函数与不可重入函数
查看>>
简单Linux C线程池
查看>>
内存池
查看>>
输入设备节点自动生成
查看>>
GNU hello代码分析
查看>>
Qt继电器控制板代码
查看>>
wpa_supplicant控制脚本
查看>>
gstreamer相关工具集合
查看>>
RS232 四入四出模块控制代码
查看>>
gstreamer插件之 videotestsrc
查看>>
linux 驱动开发 头文件
查看>>
/etc/resolv.conf
查看>>
container_of()传入结构体中的成员,返回该结构体的首地址
查看>>
linux sfdisk partition
查看>>
ipconfig,ifconfig,iwconfig
查看>>
opensuse12.2 PL2303 minicom
查看>>