Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我想使用一个File对象来读取与 groovlet 相同目录中的本地文件。但是,使用文件的相对路径(或"example.txt"或"./example.txt")并不能解决问题。如果我给它一个绝对路径(例如,"/example.txt"),那么它可以工作。
File
"example.txt"
"./example.txt"
"/example.txt"
有没有办法以编程方式获取 groovlet 的工作目录或上下文路径?
new File("${request.getContextPath()}/example.txt")