Java keeping config values in property file

1. File Simple.java

import java.io.FileInputStream;
import java.util.Properties;
import java.io.IOException;
import java.io.FileNotFoundException;
 
class Simple {
 
	public static void main(String[] args) {
 
	try {
 
	Properties config = new Properties();
 
	String configFile =  "config.properties";
	FileInputStream input = new FileInputStream("config.properties");
 
	config.load(input);	
 
    	String valueStr = config.getProperty("textlocal_key");
	System.out.println(valueStr);
 
	} catch (FileNotFoundException e) {
		e.printStackTrace();
	} catch (IOException e) {
		e.printStackTrace();
	}
 
   	}
}

2. Compile and run

javac Simple.java;
java Simple

Leave a Reply