简体   繁体   English

如何在 Intellij ide - java 中设置资源文件夹

[英]How to set resources folder in Intellij ide - java

I have an issue that I am trying to solve a while.我有一个问题,我正在尝试解决一段时间。 I have a project that I imported using intelilj ide.我有一个使用 intelilj ide 导入的项目。 I want to use a file that exists in my resources folder.我想使用我的资源文件夹中存在的文件。 The problem is that Intellij set the resource folder in wrong place.问题是 Intellij 将资源文件夹设置在错误的位置。 This is the command in java这是 java 中的命令

 ClassLoader classLoader = getClass().getClassLoader();
        String path = classLoader.getResource("fw8TAX12.pdf").getPath();

this is what Intelij returns:这是 Intelij 返回的内容:

X:\project\out\test\resources

however the file in in但是文件在

   X:\project\src\test\resources

I do not understand what is the out folder in my project since I did not create it, I need that getResource method return the accurate place of the resource.我不明白我的项目中的 out 文件夹是什么,因为我没有创建它,我需要 getResource 方法返回资源的准确位置。

I navigate to modules in intelij and under Resources and test resources tab, select the correct path, and nothing intelij just goes to the out folder and not to the src folder.我导航到 intelij 中的模块和资源和测试资源选项卡下,select 是正确的路径,没有任何 intelij 只是进入 out 文件夹而不是 src 文件夹。 how can I make intelij understand what is the correct resources path我怎样才能让 intelij 了解什么是正确的资源路径

在此处输入图像描述

在此处输入图像描述

another try to set the resource folder that not worked另一个尝试设置不起作用的资源文件夹在此处输入图像描述

In project frame, right click directory -> mark as -> Resources.在项目框架中,右键单击目录 -> 标记为 -> 资源。 Or click the Resources button in the header in your first screen shot (with that directory selected as shown).或者在您的第一个屏幕截图中单击 header 中的资源按钮(如图所示选择该目录)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM