您的位置:首页 > 编程语言 > Java开发

java中Properties有什么用,举例说明?

2017-04-14 21:39 225 查看
马克-to-win:Properties里面存着也是键值对,而且它更方便java对配置文件,字符串的操作,

例:3.9.1

import java.util.*;

public class TestMark_to_win {

public static void main(String args[]) {

Properties sala = new Properties();

Set name;

String str;

sala.put("zs", "1111");

sala.put("ls", "2222");

sala.put("ww", "3333");

sala.put("zl", "4444");

// Show all name and sala in hashtable.

name = sala.keySet(); // get set-view of keys

Iterator itr = name.iterator();

while (itr.hasNext()) {

str = (String) itr.next();

System.out.println("The sala of " +

/* public String getProperty(String key)Searches for the property

* with the specified key in this property list.*/

str + " is " + sala.getProperty(str) + ".");

}

System.out.println();

// look for state not in list -- specify default

/*

* Searches for the property with the specified key in this property

* list. The method returns the default value argument if the property

* is not found.

*/

str = sala.getProperty("Mark", "Not Found");

System.out.println("The sal of Mark is " + str + ".");

}

}

结果:

。。。。。。。。。。。。。。。。。

详情黏贴以下网址在地址栏后请进:http://www.mark-to-win.com/JavaBeginner/JavaBeginner7_web.html#DefinitionUsageOfProperties
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息