Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Intellij - how do I add a text file to the resources

I am reading a *.properties file using properties.load and a file name.

I want to add the properties file to the jar or to the classpath.

  1. How do add a file to the jar?
  2. How do I read from the jar?
like image 350
Bick Avatar asked Dec 29 '25 02:12

Bick


1 Answers

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);
like image 200
CrazyCoder Avatar answered Dec 30 '25 22:12

CrazyCoder