Java Fundamentals Enhanced IO flow note 68:properties and IO Stream collection use

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.