JAVA basics: benefits of using the Properties class
Source: Internet
Author: User
JAVA basics: benefits of using the Properties class-general Linux technology-Linux programming and kernel information. For more information, see the following. Many developers complain that C ++ cannot bind the Properties class as Java does. The Properties class of Java contains a file which is used to read and write Properties in the Properties class. It can be written as follows: <名字> = <数值> (For example, ConnectToInternet = Use IE ).
The advantage of using the Properties class is that you can easily understand and modify them. In the first part of this article, you will see that we can also use the Properties class in C ++. The second part of this article will show you how to use the operators >>and < <把数据保存到properties类中是多么的容易。
Now we will introduce the structure of the C ++ Properties file. Each row of the file can be one of the following three situations:
Empty line (think it is part of the comment)
Comment row starting '#'
' <名字> = <数值> 'Row. This is a statement that assigns a value to an attribute.
Now let's take a look at the features of the Properties class:
Annotations are persistent (they are not lost when the Properties class is saved ). Note that each comment belongs to a certain attribute. In' <名字> = <数值> 'Line comment row belongs to this' <名字> 'Property.
After the Properties class is saved, the attributes are retained.
It is effective for various character types: char, wchar_t, etc.
The use of the Properties class is quite simple:
Save (): save attributes
Has_property (strPropertyName): If the class has this property, 'true' is returned'
String get_property (strPropertyName): returns the specified property (if the specified property does not exist, an exception is thrown)
Set_property (strPropertyName, strPropertyValue): Set the given property
Stringget_property_comment (strPropertyName): returns the comment that belongs to the specified attribute. (If the comment of the specified attribute does not exist, an exception is thrown)
Set_property_comment (strPropertyName, strPropertyComment): sets the comment for the specified attribute. (If the comment for the specified attribute does not exist, an exception is thrown)
The following is the code of the file_reader_writer class and the corresponding example. After running the command, copy the properties.txt file. Let's see how easy it is to access and modify it.
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.