在Java中的resources文件夹中获取文件 [英] Get file in the resources folder in Java

查看:152
本文介绍了在Java中的resources文件夹中获取文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I want to read the file in my resource folder in my Java project. I used the following code for that

MyClass.class.getResource("/myFile.xsd").getPath();

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

And I wanted to check the path of the file. But it gives the following path

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

我在maven存储库依赖项中获取文件路径,但它没有获取文件。我该怎么办?

I get the file path in the maven repository dependency and it is not getting the file. How can I do this?

推荐答案

您需要提供 res b。文件夹。

You need to give the path of your res folder.

MyClass.class.getResource("/res/path/to/the/file/myFile.xsd").getPath();

这篇关于在Java中的resources文件夹中获取文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆