Using Properties class:
delhi = sumit
japan = chet
bangalore = raju
chennai = ishaan
- import java.io.File;
- import java.io.FileInputStream;
- import java.io.IOException;
- import java.util.Enumeration;
- import java.util.Properties;
- public class ReadPropertiesFiles {
- public static void main(String[] args) throws IOException {
- File file = new File("D:\\contacts.properties");
- FileInputStream fis = new FileInputStream(file);
- Properties prop = new Properties();
- prop.load(fis);
- fis.close();
- Enumeration enuKeys = prop.keys();
- while (enuKeys.hasMoreElements()) {
- String key = (String) enuKeys.nextElement();
- String value = prop.getProperty(key);
- System.out.println(key + " = " + value);
- }
- }
- }
delhi = sumit
japan = chet
bangalore = raju
chennai = ishaan
No comments:
Post a Comment