Intellij - 如何向资源添加文本文件 [英] Intellij - how do I add a text file to the resources
本文介绍了Intellij - 如何向资源添加文本文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用 properties.load
和文件名读取 *。properties
文件。
I am reading a *.properties
file using properties.load
and a file name.
我想将属性文件添加到jar或类路径中。
I want to add the properties file to the jar or to the classpath.
- 如何向jar中添加文件?
- 如何从jar中读取?
推荐答案
将文件放在源文件夹中,将其复制到输出中并添加根据设置
|将类与类一起放到jar中编译器
| 资源模式
。
Place the file in the source folder, it will be copied to the output and added to the jar together with the classes according to Settings
| Compiler
| Resource Patterns
.
要在您的应用中加载文件,请使用以下内容:
To load the file in your app use something like:
Properties props = new Properties();
InputStream is = this.getClass().getResourceAsStream("/file.properties");
props.load(is);
这篇关于Intellij - 如何向资源添加文本文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文