Properties屬性集合

2021-08-19 18:21:20 字數 1328 閱讀 5545

properties屬性集合概述

*是乙個雙列集合,實現了map介面,繼承hashtable類。

properties集合的特點

*建立物件時不需要指定泛型

*鍵和值都是字串

*可以和流技術相加使用

*可以直接通過流將集合中的資料儲存到檔案中

*可以直接從檔案中讀取資料到集合

​屬性檔案要求

*命名要求:***x.properties

*儲存格式:每個鍵值對佔據一行,格式:鍵=值

*檔案中可以使用注釋,注釋是以#開頭

​properties類常用方法

*object

setproperty(string

key, string

value)

*儲存鍵值對

如果鍵存在,則使用新值替換舊值,返回舊值,否則返回null

*string

getproperty(string

key)

*根據鍵獲得值

*int

size(); 獲得鍵值對個數

*object

remove(object

key) 根據鍵刪除鍵值對,返回鍵對應的值

*set

<

string

>

stringpropertynames() 獲得集合中的所有鍵

*void

store(writer

writer, string

comments)

*void

store(outputstream

out, string

comments)

*將集合中的資料儲存到流關聯的目標檔案中

*comments:描述資訊字串,一般給null即可

*void

load(inputstream

in)*

void

load(reader

reader)

*從流關聯的目標檔案中讀取資料到集合中

示例**

public

class

propertiesdemo

/*** properties集合:儲存資料到檔案中

*/public

static

void

test02() throws

exception

/*** properties集合常用方法演示

*/public

static

void

test01()

}}

屬性集合類Properties

hashtable implements map public class properties extends hashtable object,object properties 是map的子類 有map的方法 方法 put key,value set keyset prop.put 0001 ...

Properties集合整理

properties集合特點 1 該集合的鍵和值都是字串型別 2 集合中的資料可以儲存到流中或從流中獲取資料 properties常用方法 儲存元素 prop.setproperty zhangsan 20 prop.setproperty wangwu 25 prop.setproperty li...

Properties集合的使用

properties集合是唯一乙個可以和io流相結合的集合 可以將集合中的資料持久化儲存,也可以將硬碟上的資料載入到該集合中。1 private static void show01 14 1 store 持久化資料 2private static void show02 throws ioexce...