更新时间:2023-12-05 14:08:52
您正确的是 new File(。)。getCanonicalPath ()
不起作用。返回工作目录。
You are correct that new File(".").getCanonicalPath()
does not work. That returns the working directory.
获取脚本目录
To get the script directory
scriptDir = new File(getClass().protectionDomain.codeSource.location.path).parent
获取脚本文件路径
To get the script file path
scriptFile = getClass().protectionDomain.codeSource.location.path