Properties(配置信息类):主要用于生产配置文件和读取配置文件信息。

----> 是一个集合类 继承HashTable 存值是以键-值的方式。

package com.beiwo.io;

import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Map.Entry;
import java.util.Properties;
import java.util.Set; public class demo5 { public static void main(String[] args) throws IOException {
// 调用方法
creatPeoperties();
readPeoperties();
} }

写入配置信息方法:

    public static void creatPeoperties() throws IOException {
// 创建properties对象
Properties properties = new Properties();
// 配置信息 键 和值都是字符串
properties.setProperty("张三", "123");
properties.setProperty("李四", "234");
properties.setProperty("王五", "345");
properties.setProperty("赵六", "456");
properties.setProperty("宋七", "567"); // 将配置信息写入磁盘中
properties.store(new FileWriter("C:\\Users\\cdlx2016\\Desktop\\2\\User.properties"), "这是用户配置信息"); }

读取配置的信息

    public static void readPeoperties() throws IOException, IOException {
// 创建peoperties对象
Properties properties = new Properties();
properties.load(new FileReader("C:\\Users\\cdlx2016\\Desktop\\2\\User.properties")); // 遍历配置信息
Set<Entry<Object, Object>> entrys = properties.entrySet();
for (Entry<Object, Object> entry : entrys) {
System.out.println("key: " + entry.getKey() + " -- value: " + entry.getValue());
} }

java Properties 配置信息类的更多相关文章

  1. java 配置信息类 Properties 的简单使用

    Properties :(配置信息类) 是一个表示持久性的集合 ,继承 Hashtable ,存值是以键-值得方式  主要用于生产配置文件和读取配置文件信息. 简单的实例: import java.i ...

  2. Html.java 存储页面信息类

    Html.java 存储页面信息类 package com.iteye.injavawetrust.miner; /** * 存储页面信息类 * @author InJavaWeTrust * */ ...

  3. spring boot mybatis XML文件读取properties配置信息

    配置文件application.properties中相关配置信息可以在部署以后修改,引用配置信息可以在代码和mybatis的映射文件中 1.JAVA代码 可以通过变量去读取 application. ...

  4. JAVA 获取jdbc.properties配置信息

    Properties myProperty = new Properties();String jdbcPath = PathKit.getWebRootPath()+File.separator+& ...

  5. 读取.properties配置信息

    package com.ctcti.webcallcenter.utils; import java.io.FileInputStream;import java.io.FileNotFoundExc ...

  6. Java properties配置文件工具类

    /* * Copyright (c) 2017. Panteng.Co.Ltd All rights reserved */ import org.apache.log4j.Logger; impor ...

  7. java将配置信息写在数据库(利用反射)

    Demo出处: 1. package com.fpx.pcs.prealert.process.xml.service.impl; public class CainiaoPushMessageSer ...

  8. Properties --- C++读配置信息的类(一)

    http://blog.csdn.net/billow_zhang/article/details/4304980 在开发实践中,积累了一些通用的C++ 类库,在此写出来给大家分享.也希望能给出更好的 ...

  9. Properties --- C++读配置信息的类

    http://blog.csdn.net/billow_zhang/article/details/4304980 在开发实践中,积累了一些通用的C++ 类库,在此写出来给大家分享.也希望能给出更好的 ...

随机推荐

  1. ZOJ 3699 Dakar Rally

    Dakar Rally Time Limit: 2 Seconds      Memory Limit: 65536 KB Description The Dakar Rally is an annu ...

  2. CF memsql Start[c]UP 2.0 B

    CF memsql Start[c]UP 2.0 B B. Distributed Join time limit per test 1 second memory limit per test 25 ...

  3. [解决WebClient或HttpWebRequest首次连接缓慢问题]

    [编程环境]Visual Studio 2010, NET4.0 [开发语言]C#, 理论上VB.NET等依赖.NET Framework框架的语言均受此影响 [问题描述] 使用HttpWebRequ ...

  4. 清理系统 cmd

    echo 正在清除系统垃圾文件,请稍等......del /f /s /q %systemdrive%*.tmpdel /f /s /q %systemdrive%*._mpdel /f /s /q ...

  5. block、inline、inline-block

    block: block - 块级元素 常见的块级元素包括:div,form,p,table,ul,ol,dl,h1~h6,pre block 可以包含 inlne 和 block 和 inline- ...

  6. 让EF飞一会儿:如何用Entity Framework 6 连接Sqlite数据库

    获取Sqlite 1.可以用NuGet程序包来获取,它也会自动下载EF6 2.在Sqlite官网上下载对应的版本:http://system.data.sqlite.org/index.html/do ...

  7. PHP 函数(数组字符串)

    函数四要素:  参数  变量   返回值  函数体 函数分类: 1.有参数的函数: function Show() { echo "hello"; } Show(); 2. 有返回 ...

  8. jquery中使用serialize() 序列化表单时 中文乱码问题

    序列化中文时之所以乱码是因为.serialize()调用了encodeURLComponent方法将数据编码了 解决方法就是进行解码 1 原因:.serialize()自动调用了encodeURICo ...

  9. Windows phone 8.1布局控件

    布局控件(4种  第一种) Grid:相当于 HTML 中的 Table 标签,但是注意 Table 更重要的是展示数据,   而 Grid 则是专门为布局所生 属性标记: Grid.RowDefin ...

  10. python初学杂记

    python常用命令: 1.python 或者 python3  打开交互式python解释器 2.python hello.py   通过命令提示符运行python脚本 交互式python解释器常用 ...