一、Properties 概述

  Properties 是Hashtable的子类,不允许key和value是null,并且它的key和value的类型都是String。

二、常用方法

  1、构造方法

Properties():创建一个无默认值的空属性列表。
Properties(Properties defaults):创建一个带有指定默认值的空属性列表

  2、获取方法

 String getProperty(String key):用指定的键在此属性列表中搜索属性。
String getProperty(String key, String defaultValue):用指定的键在属性列表中搜索属性

  3、设置方法

 Object setProperty(String key, String value):调用 Hashtable 的方法 put。 

  4、其他方法

 void load(InputStream inStream):从输入流中读取属性列表(键和元素对)。
void load(Reader reader) :按简单的面向行的格式从输入字符流中读取属性列表(键和元素对)。

  

  Demo:

   @Test
public void test1(){
Properties pro = new Properties();
pro.setProperty("user", "root");
pro.setProperty("pwd", "123456"); String user = pro.getProperty("user");
String password = pro.getProperty("pwd");
System.out.println(user);
System.out.println(password);
}   @Test
public void test2() throws IOException{
Properties pro = new Properties();
pro.load(TestMapImpl.class.getClassLoader().getResourceAsStream("jdbc.properties")); String user = pro.getProperty("user");
String password = pro.getProperty("password");
System.out.println(user);
System.out.println(password);
}   @Test
public void test3() throws IOException{
Properties pro = System.getProperties();//获取系统属性配置
Set entrySet = pro.entrySet();
for (Object entry : entrySet) {
System.out.println(entry);
}
}

Java 之 Properties 集合的更多相关文章

  1. java基础知识回顾之java集合类-Properties集合

    /** java.lang.Object   |--java.util.Dictionary<K,V>      |--java.util.Hashtable<Object,Obje ...

  2. Java中Properties集合总结

    一:定义 表示一个持久的集,可以存在流中或者从流中加载.用来读取Java的配置文件,在Java中为.properties为后缀名的文本文件. 二:特点 是 Hashtable子类,map集合方法都可以 ...

  3. 属性集合java.util.Properties

    属性集合java.util.Properties java.util.Properties集合 extends Hashtable<k, v> implements Map<k, v ...

  4. Java Properties集合基础解析

    Java Properties集合基础解析 本期学习的properties集合是项目中经常用到的操作 什么是Properties集合? java.util.Properties集合继承于Hashtab ...

  5. java的缓冲流及使用Properties集合存取数据(遍历,store,load)

    缓冲流 概述 字节缓冲流:BufferedInputStream,BufferedOutputStream 字符缓冲流:BufferedReader,BufferedWriter 缓冲流原理 缓冲区是 ...

  6. java学习笔记—集合之Map集合

    p.p1 { margin: 0.0px 0.0px 0.0px 0.0px; text-align: center; font: 12.0px Times } p.p2 { margin: 0.0p ...

  7. Java 之 Properties类 属性集

    一.概述 java.util.Properties集合 extends Hashtable<k,v> implements Map<k,v> java.util.Propert ...

  8. Properties集合与IO流

    package com.itheima.demo07.Prop; import java.io.FileOutputStream; import java.io.FileReader; import ...

  9. 使用Properties集合存储数据,遍历取出Properties集合中的数据和Properties集合中的方法store和load

    package com.yang.Test.PropertiesStudy; import java.io.FileWriter; import java.io.IOException; import ...

随机推荐

  1. java执行hive命令或者脚本

    java执行脚本 import java.io.*; import java.text.DateFormat; import java.text.SimpleDateFormat; import ja ...

  2. JavaMap常用操作

    判断key值是否存在 map.containsKey("youkey") 根据key修改value值 map.put("youkey","you ne ...

  3. leetcode203. 移除链表元素

    方法一(删除头结点时另做考虑) class Solution { public: ListNode* removeElements(ListNode* head, int val) { if(head ...

  4. requests--超时设置,代理设置,身份认证

    超时设置 你可以告诉 requests 在经过以 timeout 参数设定的秒数时间之后停止等待响应.基本上所有的接口都应该使用这一参数.如果不使用,你的程序可能会永远失去响应 import requ ...

  5. [LeetCode] 234. Palindrome Linked List 回文链表

    Given a singly linked list, determine if it is a palindrome. Example 1: Input: 1->2 Output: false ...

  6. [LeetCode] 4. Median of Two Sorted Arrays 两个有序数组的中位数

    There are two sorted arrays nums1 and nums2 of size m and n respectively. Find the median of the two ...

  7. SpringBootThymeleaf案例

    一.添加依赖 <!-- 添加thymeleaf模版的依赖 --> <dependency> <groupId>org.springframework.boot< ...

  8. k8s学习路线

    1. 核心概念说明 http://dockone.io/article/932 https://www.centos.bz/2017/08/k8s-kubernetes-architecture-di ...

  9. 【对不同形式矩阵的总结】WC 2009 最短路径问题(线段树+矩阵乘法)

    题意 ​ 题目链接:https://www.luogu.org/problem/P4150 ​ 一个 \(6\times n\) 的网格图,每个格点有一个初始权值.有两种操作: 修改一个格子的权值 求 ...

  10. QLayout及其子类 清除添加的widget

    起初,我的思路是,先取得Layout的items数量, 然后通过索引来移除每一个items,代码如下: QHBoxLayout * hly = new QHBoxLayout; ; i < ; ...