Saturday, 10 June 2017

Java Tutorial: Java properties [How to print the property list out to the specified print writer] ~ foundjava


Click here to watch in Youtube :
https://www.youtube.com/watch?v=Vg30T1Yg7eo&list=UUhwKlOVR041tngjerWxVccw

db.properties
user=root 
password=oracle 

PropertiesDemo.java
import java.io.FileReader;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Properties;

/*
 * public void list(PrintWriter out)
 * 
 * Parameters:
 * ----------
 * 
 * out - an output stream.
 */
class PropertiesDemo
{

    public static void main(String[] args) throws IOException
    {

        try (FileReader fileReader = new FileReader("db.properties");)
        {

            Properties p = new Properties();
            /*
             * Reads a property list (key and element pairs)
             * from the input character stream in a simple
             * line-oriented format.
             */
            p.load(fileReader);

            PrintWriter writer = new PrintWriter(System.out);
            /*
             * print the list with a PrintWriter object
             */
            p.list(writer);

            /*
             * flush the stream
             */
            writer.flush();

        }

    }
}
Output
-- listing properties --
user=root 
password=oracle 

Click the below link to download the code:

CLICK HERE

No comments:

Post a Comment