Intellij - 如何向资源添加文本文件

时间:2011-09-26 14:16:56

标签: intellij-idea

我正在使用*.properties和文件名读取properties.load文件。

我想将属性文件添加到jar或类路径中。

  1. 如何将文件添加到jar?
  2. 我如何从罐子里读取?

1 个答案:

答案 0 :(得分:8)

将文件放在源文件夹中,它将被复制到输出中,并根据Settings |的类与类一起添加到jar中。 Compiler | Resource Patterns

要在您的应用中加载文件,请使用以下内容:

Properties props = new Properties();
InputStream is = this.getClass().getResourceAsStream("/file.properties");
props.load(is);
相关问题