Ask Your Question
2

What is the way to reach a configuration file contained in the jar?

asked 2023-05-15 06:20:13 +0000

bukephalos gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2023-05-15 06:40:01 +0000

nofretete gravatar image

In order to reach a configuration file contained in a jar file, you can use the following code snippet:

InputStream inputStream = getClass().getResourceAsStream("/config/config.properties");
Properties properties = new Properties();
properties.load(inputStream);

This code assumes that the configuration file is located in a folder named "config" at the root of your jar file. The getResourceAsStream method retrieves the file as an InputStream, which can be read using a Properties object to access individual properties.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2023-05-15 06:20:13 +0000

Seen: 14 times

Last updated: May 15 '23