Properties of common Java classes

Source: Internet
Author: User
Tags list of attributes

1. Features

The Properties class represents a persistent set of attributes that can be stored in a stream or loaded from a stream, enabling memory and file intersection

Properties inherit the Hashtable<object,object> class and can use methods such as Add (), AddAll (), but they only support

A string type of key and value, so methods such as setproperty () are defined inside the properties to ensure type safety. In its associated text

Each property inside the piece is represented by this: Key=value.

2. Methods

Load (InputStream in) Reading a list of attributes from an input stream
SetProperty (string key, String value) Call Hashtable's put () method
GetProperty (String key) Call Hashtable's Get () method
Store (OutputStream out, String comments) Write the property list to the output stream
List (OutputStream out) Output a property list to a specified output stream

3. Use

Code

public class Propertiesdemo {

public static void Main (string[] args) throws IOException {

File File = new file ("C:properties.txt");

Properties P = new properties ();

Add Property key value

P.setproperty ("A", "97");

P.setproperty ("B", "98");

P.setproperty ("C", "99");

P.setproperty ("D", "100");

P.setproperty ("B", "100");

Write to specified file

P.store (new FileOutputStream (file), null);

Reads the property key value from the specified file

P.load (new FileInputStream (file));

In the console output

P.list (System.out);

}

}

Operation Result:---listing properties--b=100a=97d=100c=99 at the same time, in the C-disk directory to generate the corresponding

Properties.txt file.


Technology sharing: www.kaige123.com

This article from the "11247808" blog, reproduced please contact the author!

Properties of common Java classes

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.