Java“user.dir"财产 - 它究竟是什么意思? [英] Java "user.dir" property - what exactly does it mean?
问题描述
我想使用 user.dir
目录作为我的单元测试的基本目录(这会创建很多文件).此属性指向当前工作目录是否正确(例如,由 'cd' 命令设置)?
I want to use user.dir
dir as a base dir for my unit tests (that creates a lot of files). Is it correct that this property points to the current working directory (e.g. set by the 'cd' command)?
推荐答案
它是运行 java
的目录,您从那里启动 JVM.不必位于用户的主目录中.它可以在用户有权运行 java 的任何地方.
It's the directory where java
was run from, where you started the JVM. Does not have to be within the user's home directory. It can be anywhere where the user has permission to run java.
所以如果你cd
进入/somedir
,然后运行你的程序,user.dir
将是/somedir
>.
So if you cd
into /somedir
, then run your program, user.dir
will be /somedir
.
另一个属性 user.home
是指用户目录.如 /Users/myuser
或 /home/myuser
或 C:Usersmyuser
.
A different property, user.home
, refers to the user directory. As in /Users/myuser
or /home/myuser
or C:Usersmyuser
.
请参阅此处了解系统属性及其说明的列表.
See here for a list of system properties and their descriptions.
这篇关于Java“user.dir"财产 - 它究竟是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!