user1788115
user1788115

Reputation: 81

How to update or modify property file in web application

I am able to load property file using InputStream but after modifying not able to update .

FileOutputStream output = 
            new FileOutputStream("/src/main/resources/test.properties");
props.store(output, "Last Time the file have been modified at:");

How to update ? any suggestion...

Upvotes: 1

Views: 1732

Answers (1)

Stephen C
Stephen C

Reputation: 718886

It is difficult to be sure what you actually mean here, but it looks to me like you want your webapp to update a properties file that it read using getResource or getResourceAsStream. This could be difficult to impossible, and it is definitely a bad idea.

The best idea would be to store the properties in tables in the webapp's database. But if you don't have a database, then you could store the properties file somewhere in the file system ... provided this is allowed.

The only file system that is guaranteed to exist and to be writable to a webapp is its temporary filespace: https://stackoverflow.com/a/2663250/139985. But of course if you get to choose and configure the web container and / or the host operating system, you could find other (container / OS specific) places to store state that is less temporary. The catch is that your solution is liable to be non-portable.

Upvotes: 1

Related Questions