Skip to main content

Read Properties file using java 


package com.pukhraj.blog;

import java.io.FileInputStream;
import java.util.Properties;


public class ReadPropertiesFile {
        public static void main(String[] args) {
                Properties prop = new Properties();
                try {
                FileInputStream in = new FileInputStream("PropertiesFilePath"); 
                        prop.load(in);
                        String name = prop.getProperty("name");
                        String address = prop.getProperty("address");
                        String city = prop.getProperty("city");
                        System.out.println("Name: " + name);
                        System.out.println("Address: " + address);
                        System.out.println("City: " + city);
                } catch (Exception e) {
                e.printStackTrace();
                }
        }
}


/*
abc.properties

name=Pukhraj
address=Dwarka
city=Delhi

*/

Comments

Popular posts from this blog

Common Eclipse Shortcuts for Java Developer Open Resource : ctrl+shift+r Quick Outline : ctrl+o Assign to local variable : ctrl+2, L Rename : alt+shift+r  Extract Local Variable : alt+shift+l  Extract Method : alt+shift+m

Copy Content of One file to another file using Java

Copy Content of One file to another file using Java. package com.pukhraj.blog; import java.io.File; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class FileCopy { public static void main(String[] args) throws IOException {   File inFile = new File("FullPath/inputFileName.extension"); File outFile = new File("FullPath/outputFileName.extension");    FileReader in = new FileReader(inFile);    FileWriter out = new FileWriter(outFile);    int i;    while ((i = in.read()) != -1)      out.write(i);    in.close();    out.close();   } }