Configuration file Class Properties

Source: Internet
Author: User
Tags list of attributes

Properties (Profile Class): Information that is used primarily for production configuration files and for reading configuration files.

Properties belong to the collection class and inherit from Hashtable.

Properties to note the details:
1. If the configuration file information once used in Chinese, then use the store method to generate the configuration file can only use character stream to solve, if the use of byte stream generated configuration file, the default is to use the Iso8859-1 Code table for encoding storage, this time will be garbled.
2. If the content in the properties changes, be sure to reuse the properties to generate the configuration file, or the profile information will not change.

Common methods:

1. Construction Method:

Properties()Creates a list of empty properties with no default values.

Properties(Properties defaults)Creates a list of empty properties with the specified default value.

2. Common methods

void load(InputStream inStream) reads the list of attributes (key and element pairs) from the input stream.

void load(Reader reader) reads the list of attributes (key and element pairs) from the input character stream in a simple line-oriented format.

void store(OutputStream out, String comments) load(InputStream) writes the list of Properties Properties attributes (key and element pairs) in this table to the output stream in a format that is appropriate for the use of methods loaded into the table.

void store(Writer writer, String comments) load(Reader) Properties writes the list of attributes (key and element pairs) in this table to the output character in a format that is appropriate for using the method.

Object setProperty(String key, String value) calls the Hashtable method put .

String getProperty(String key) searches for properties in this property list with the specified key.

Actual combat: The use of properties to achieve the software can only run three times, more than three times after the prompt purchase of genuine and the introduction of the JVM.

Code examples such as the following

1 ImportJava.io.File;2 ImportJava.io.FileReader;3 ImportJava.io.FileWriter;4 Importjava.io.IOException;5 Importjava.util.Properties;6 7 8  Public classdemoproperties {9     Ten      Public Static voidMain (string[] args)throwsIOException { OneFile File =NewFile ("E:\\nick.property"); A         if(!file.exists ()) { - file.createnewfile (); -         } theProperties Properties =NewProperties (); -Properties.load (Newfilereader (file)); -         intCount = 0; -String value = Properties.getproperty ("Number of logins"); +         if(value!=NULL ) { -Count =Integer.parseint (value); +         } Acount++; at         if(count>=3) { -System.out.println ("The trial period has expired, please purchase a genuine.") "); -System.exit (0); -         } -          -Properties.setproperty ("Login number", count+ "" "); inProperties.store (NewFileWriter (file), "Number of logins" +count); -     } to  +}
View Code

Configuration file Class Properties

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.