可以使用以下代码获取当前工作目录: ```java import org.springframework.core.io.Resource; import org.springframework.core.io.support.PathMatchingResourcePatternResolver; public class CurrentWorkingDirectoryExample { public static void main(String[] args) throws Exception { PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver(); Resource resource = resolver.getResource("file:./"); System.out.println("Current working directory: " + resource.getFile().getAbsolutePath()); } } ``` 这里使用了Spring的`PathMatchingResourcePatternResolver`类来获取当前工作目录。该类提供了一种方便的方式来解析资源路径,包括文件系统路径、类路径、URL等。在这个例子中,我们使用`file:./`来指定当前工作目录,并使用`getResource()`方法来获取`Resource`对象。最后,我们使用`getFile()`方法来获取文件对象,并使用`getAbsolutePath()`方法来获取绝对路径。