package com.mindprod.example;

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

/**
 * example use of java.util.Properties for non-system, user Properties.
 * <p/>
 * composed with IntelliJ IDEA
 *
 * @author Roedy Green, Canadian Mind Products
 * @version 1.0
 */
public final class TestProperties
    {
// --------------------------- main() method ---------------------------

    /**
     * TEST harness
     *
     * @param args not used
     * @throws IOException Let Java report any problem.
     */
    public static void main( String[] args ) throws IOException
        {
        Properties props = new Properties();
        FileInputStream fis =
                new FileInputStream( "C:/temp/sample.properties" );
        props.load( fis );
        fis.close();
        String desc = props.getProperty( "window.logo" );
        System.out.println( desc );

        // changing a property and saving the properties
        props.setProperty( "window.logo", "resources/sunLogo.png" );

        FileOutputStream fos =
                new FileOutputStream( "C:/temp/updatedsample.properties" );
        // saving will lose your comments, lose blank lines, and scramble the
        // order.
        props.store( fos, "sample properties with comments lost" );
        fos.close();
        }
    }