Monday, 27 May 2019

Java: Write Properties to System.out


Using ‘store’ method of properties, you can write system properties to standard output.

Example
Properties props = new Properties();
props.store(System.out, "Application Properties");

App.java
package com.sample.app;

import java.io.IOException;
import java.util.Properties;

public class App {

      public static void main(String args[]) throws IOException {
            Properties props = new Properties();

            props.setProperty("version", "1.23");
            props.setProperty("vendor", "ABC Corporation");
            props.setProperty("userQuery", "where value = 'wab12'");

            props.store(System.out, "Application Properties");
      }

}

Output
#Application Properties
#Mon May 27 11:43:49 IST 2019
version=1.23
userQuery=where value \= 'wab12'
vendor=ABC Corporation


You may like

No comments:

Post a Comment