package com.mindprod.example;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Enumeration;
import java.util.Properties;
import static java.lang.System.*;
/**
* example use of java.util.Properties for non-system, user Properties.
*
* @author Roedy Green, Canadian Mind Products
* @version 1.1 2008-07-30
* @since 2009
*/
public final class TestProperties
{
/**
* TEST harness
*
* @param args not used
*
* @throws java.io.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 logoPng = props.getProperty( "window.logo" );
out.println( "window.logo" + "=[" + logoPng + "]" );
int height = Integer.parseInt( props.getProperty( "height", "25" ) );
out.println( "height" + "=[" + height + "]" );
props.setProperty( "window.logo", "resources/sunLogo.png" );
Enumeration keys = props.keys();
while ( keys.hasMoreElements() )
{
String keyword = ( String ) keys.nextElement();
String value = ( String ) props.get( keyword );
out.println( keyword + "=[" + value + "]" );
}
FileOutputStream fos =
new FileOutputStream( "C:/temp/updatedsample.properties" );
props.store( fos, "sample properties with comments lost" );
fos.close();
}
}