package edu.uchicago.cs.java.finalproject.tronscan.examples;


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

//http://www.mkyong.com/java/java-properties-file-examples/
public class ConfigFile {


	public static void main(String[] args) {
		
		writeOut();
		readIn();
		
		
	}
	

    public static void writeOut( )
    {
    	Properties prop = new Properties();
 
    	try {
    		//set the properties value
    		prop.setProperty("dirForJpegs", "c:/cspp/qz-5106-01/");
    		prop.setProperty("dbuser", "mkyong");
    		prop.setProperty("dbpassword", "password");
 
    		//save properties to project root folder
    		prop.store(new FileOutputStream("tronscan.config"), null);
 
    	} catch (IOException ex) {
    		ex.printStackTrace();
        }
    }
	    
	    
	    private static void readIn(){
	    	
	    	
	    	Properties prop = new Properties();
	    	 
	    	try {
	               //load a properties file
	    		prop.load(new FileInputStream("config.properties"));
	 
	               //get the property value and print it out
	                System.out.println(prop.getProperty("database"));
	    		System.out.println(prop.getProperty("dbuser"));
	    		System.out.println(prop.getProperty("dbpassword"));
	 
	    	} catch (IOException ex) {
	    		ex.printStackTrace();
	        }
	    }


}
