1. Properties and IO Stream collection use
The collection here must be a Properties collection :
public void load (Reader reader): reads the data from the file into the collection
public void Store (Writer writer,string comments): Storing data in a collection to a file
2. Code implementation:
1 Packagecn.itcast_08;2 3 ImportJava.io.FileReader;4 ImportJava.io.FileWriter;5 Importjava.io.IOException;6 ImportJava.io.Reader;7 ImportJava.io.Writer;8 Importjava.util.Properties;9 Ten /* One * The collection here must be a Properties collection: A * public void load (Reader reader): reads the data from the file into the collection - * public void Store (Writer writer,string comments): Storing data in a collection to a file - * the * Stand-alone version of the game: - * Progress save and load. - * Three Kingdoms, kingdoms, the Paladin biography ... - * + * BU =1 - * Fang =1 + */ A Public classPropertiesDemo3 { at Public Static voidMain (string[] args)throwsIOException { - //myload (); - - mystore (); - } - in Private Static voidMystore ()throwsIOException { - //To create a collection object toProperties prop =NewProperties (); + -Prop.setproperty ("Brigitte", "27"); theProp.setproperty ("Wu Xin", "30"); *Prop.setproperty ("Lynn Qu", "18"); $ Panax Notoginseng //Public void Store (Writer writer,string comments): Storing data in a collection to a file -Writer W =NewFileWriter ("Name.txt"); theProp.store (W, "HelloWorld"); + w.close (); A } the + Private Static voidMyload ()throwsIOException { -Properties prop =NewProperties (); $ $ //Public void Load (Reader reader): reads the data from the file into the collection - //Note: The data for this file must be in the form of a key-value pair -Reader r =NewFileReader ("Prop.txt"); the Prop.load (r); - r.close ();Wuyi theSystem.out.println ("Prop:" +prop); - } Wu}
Run the effect as follows:
Java Fundamentals Enhanced IO flow note 68:properties and IO Stream collection use