Use Properties to obtain properties from files

xiaoxiao2021-03-06  70

Import java.util. *; import java.io. *;

/ ** * refer to http://www-900.ibm.com/developerWorks/cn/java/j-tiger02254/index_eng.shtml
* or http://www-900.ibm.com/developerWorks / cn/java/j-tiger02254/index.shtml * / public class loadproperties {public static void main (string [] args) throws exception {property {item ();

// load properties from configuration file System.out.println ( "From properties file:"); FileInputStream fis = new FileInputStream ( "sample.properties"); prop.load (fis); prop.list (System.out); System.out.println ("/ NTHE Foo Property:" Prop.GetProperty ("foo"))); // load proties from xml property file (tiger new method) System.out.println ("from xml file:") !; fis = new FileInputStream ( "sampleprops.xml"); / ** *

 The XML document must have the following DOCTYPE declaration: *  * The dtd file: *  *  *  *  *  *  *  *  * / Prop.LoadFromXML (FIS); Prop.List (System.out); System.out.Println ("/ NTHE Foo Property:"   Prop.GetProperty ("foo")); / / Generate an XML file system.out.println ("Produce A XML File"); Prop = New Properties (); Prop.SetProperty ("One-TWO", "Buckle My Shoe"); Prop.SetProperty ("Three- Four "," Shut the door "); Prop.SetProperty (" Five-Six "," Pick Up Sticks "); Prop.SetProperty (" Seven-Eight "," Lay the Straight "); Prop.SetProperty (" NINE -ten "," a Big, Fat Hen "); FileOutputStream Fos = New FileoutputStream (" rhyme.xml ");

转载请注明原文地址:https://www.9cbs.com/read-90203.html

New Post(0)