在Java中的resources文件夹中获取文件

Mal*_*tha 7 java resources classpath maven

我想在我的Java项目的资源文件夹中读取该文件.我使用了以下代码

MyClass.class.getResource("/myFile.xsd").getPath();
Run Code Online (Sandbox Code Playgroud)

我想检查文件的路径.但它给出了以下路径

file:/home/malintha/.m2/repository/org/wso2/carbon/automation/org.wso2.carbon.automation.engine/4.2.0-SNAPSHOT/org.wso2.carbon.automation.engine-4.2.0-SNAPSHOT.jar!/myFile.xsd
Run Code Online (Sandbox Code Playgroud)

我在maven存储库依赖项中获取文件路径,但它没有获取文件.我怎样才能做到这一点?

Sud*_*hul 4

您需要提供文件夹的路径res

MyClass.class.getResource("/res/path/to/the/file/myFile.xsd").getPath();
Run Code Online (Sandbox Code Playgroud)