| | |

Reading the data from the property file using Java

we are using property file to store some organized data,

like database url and connection username etc.,

reading from this property file is easy and useful

myproperties.properties  // my properties file name

it`s contain

name=katta vijay
age=24
email=mail@javamix.net

Main.java     // to read data from property file

package javamixposts;

import java.io.*;
import java.util.*;

/**
*
* @author kattavijay
*/
public class Main {

       public static void main(String[] args)throws Exception {
        // TODO code application logic here
     Properties p = new Properties();  //create object for the properties
     FileInputStream fis=new FileInputStream("myproperties.properties"); // creating file input stream with properties file
     p.load(fis); //loading stream object to properties
     System.out.println("name="+p.getProperty("name")); // reading the name value from property file
     System.out.println("age="+p.getProperty("age")); // reading the age value from property file
     System.out.println("email="+p.getProperty("email")); // reading the email value from property file
     System.out.println("loading properties completed from "+p.getProperty("name")+"tfile");   // again reading the name value from property file
    }

}

output :

name=katta vijay
age=24
email=mail@javamix.net
loading properties completed from katta vijay        file

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *