Friday 10 March 2017

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


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:
https://sites.google.com/site/ramj2eev1/home/javabasics/PropertiesDemo_list_pw_App.zip?attredirects=0&d=1

Github Link:
https://github.com/ramram43210/Java/tree/master/BasicJava/PropertiesDemo_list_pw_App

Bitbucket Link:
https://bitbucket.org/ramram43210/java/src/2f1fa585daa61fc8fa0957d6f04b940eddbcf7ec/BasicJava/PropertiesDemo_list_pw_App/?at=master

See also:

  • All JavaEE Viedos Playlist
  • All JavaEE Viedos
  • All JAVA EE Links
  • Servlets Tutorial
  • All Design Patterns Links
  • JDBC Tutorial
  • Java Collection Framework Tutorial
  • JAVA Tutorial
  • Kids Tutorial
  • 2 comments:

    1. Truly a very good article on how to handle the future technology. After reading your post,thanks for taking the time to discuss this, I feel happy about and I love learning more about this topic
      Manpower Consultancy in Bangalore
      Hr Consultancy in bangalore
      Recruitment Consultancy in Bangalore

      ReplyDelete
    2. For niit projects, assignments, cycle tests, lab@homes, c#, html, java, java script, sql, oracle and much more visit http://gniithelp.blogspot.in or https://mkniit.blogspot.in

      ReplyDelete