messages.propeties
username=sachin
password=india@123
age=38
package com.usr.io;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Enumeration;
import java.util.Properties;
public class ReadPropertiesFile {
public static void main(String[] args) {
try{
File fin=new File("messages.properties");
FileInputStream fis=new FileInputStream(fin);
BufferedReader br=new BufferedReader(new InputStreamReader(fis));
Properties pr=new Properties();
pr.load(br);
br.close();
Enumeration<Object> enumKeys=pr.keys();
while(enumKeys.hasMoreElements()){
String key=(String) enumKeys.nextElement();
String value=pr.getProperty(key);
System.out.println(key+":"+value);
}
}
catch(FileNotFoundException ex){
ex.printStackTrace();
}
catch(IOException ex){
ex.printStackTrace();
}
}
}
Output
age:38
password:india@123
username:sachin