Jan 02

The Properties class has a store() method for saving a set of properties to a stream. There are lots of examples on the web that show how to use store() but unfortunately the majority of them fail to close the stream which is a bit misleading for new developers. Closing the stream is the responsibility of the caller (as mentioned in the javadoc), and failure to do it can result in the properties not being written to their ultimate destination.

Here’s an example showing how to write the properties to a file (including closing the stream).

Properties prop = new Properties();
OutputStream out = new FileOutputStream("my.properties"); 
try {
     prop.setProperty("abc", "123");
     prop.store(out, null);
} catch (IOException ex) {
} finally {

written by objects \\ tags: , , ,

Jan 31

A session can be closed by calling the invalidate() method of the HttpSession class.


written by objects \\ tags: , , ,