java 如何从 IntelliJ IDEA 中的资源文件夹访问图像而无需提供完整路径名
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/33314388/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to access images from a resource folder in intelliJ IDEA without having to give entire path name
提问by Hobbs2000
How would I do something like this in intelliJ IDEA
我将如何在 intelliJ IDEA 中做这样的事情
File file = new File("C:\Users\Account\Documents\ProjectFolder\ResourceFolder\image");
But not have to enter the whole file path in. I'm pretty sure there is a way, and I'm fairly certain it has something to do with adding it to my build path. I know how to do that in Eclipse but not in intelliJ.
Thanks in advance!
但不必输入整个文件路径。我很确定有一种方法,而且我很确定它与将它添加到我的构建路径有关。我知道如何在 Eclipse 中做到这一点,但在 intelliJ 中不知道。
提前致谢!
回答by uwolfer
You should use Java resource loading system. This is not depending on your IDE. Once you have marked a folder as resource folderin IntelliJ, it is available in your code as via resource loader.
您应该使用 Java 资源加载系统。这不取决于您的 IDE。一旦您在 IntelliJ中将文件夹标记为资源文件夹,它就可以通过资源加载器在您的代码中使用。