【Java开源代码栏目提醒】:网学会员为需要Java开源代码的朋友们搜集整理了XMLPropertiesSimpleTest.java相关资料,希望对各位网友有所帮助!
import java.io.*;
import java.util.*;
public class XMLPropertiesSimpleTest
{
public static void main(String args[])
{
XMLProperties props;
HashMap defaults = new HashMap();
FileOutputStream fileOut;
FileInputStream fileIn;
defaults.put("stephen","black");
defaults.put("cheryl","purple");
props = new XMLProperties(defaults);
props.setProperty("scott","blue");
props.setProperty("sue","green");
System.out.println("Before");
System.out.println("Stephens favorite color is: "+props.getProperty("stephen"));
System.out.println("Scotts favorite color is: "+props.getProperty("scott"));
System.out.println("Cheryls favorite color is: "+props.getProperty("cheryl"));
System.out.println("Sues favorite color is: "+props.getProperty("sue"));
try
{
fileOut = new FileOutputStream("c:\\temp\\props.xml");
props.store(fileOut);
fileOut.close();
props = new XMLProperties();
fileIn = new FileInputStream("c:\\temp\\props.
xml");
props.load(fileIn);
fileIn.close();
}
catch(Exception exp)
{
System.out.println(exp);
}
System.out.println();
System.out.println("After");
System.out.println("Stephens favorite color is: "+props.getProperty("stephen"));
System.out.println("Scotts favorite color is: "+props.getProperty("scott"));
System.out.println("Cheryls favorite color is: "+props.getProperty("cheryl"));
System.out.println("Sues favorite color is: "+props.getProperty("sue"));
}
}