Opening a local file in Groovy

2.2k views Asked by At

I want to use a File object to read a local file in the same directory as a groovlet. However, using a relative path to the file (either "example.txt" or "./example.txt") doesn't do the trick. If I give it an absolute path (e.g., "/example.txt"), then it works.

Is there any way to get the working directory or context path of the groovlet programmatically?

1

There are 1 answers

1
Aaron Saunders On BEST ANSWER
new File("${request.getContextPath()}/example.txt")