Properties资源文件工具类
来源:互联网 发布:淘宝宝贝怎么靠前 编辑:程序博客网 时间:2024/05/22 03:25
package com.ctl.util;import java.io.File;import java.io.FileInputStream;import java.io.FileNotFoundException;import java.io.FileOutputStream;import java.io.IOException;import java.util.HashMap;import java.util.Map;import java.util.Properties;/** * @deprecated 该类可以用来创建properties资源文件 * @author Administrator * @see www.ctl.com.cn * @category SDGHDHSDFG * @serial dfgds */public class PropertiesUtil {/** * * @param propertityPath * 资源文件要存放的路径例如H:/mysql.properties * @param map * 将要写入的资源放入该map中 HashMap<String, String> * @param comment * 对在资源文件的描述 */public static void createPropertityFile(String propertityPath, String comment, Map<String, String> map) {File file = new File(propertityPath);new File(file.getParent()).mkdirs();Properties pro = new Properties();for (Map.Entry<String, String> entry : map.entrySet()) {pro.setProperty(entry.getKey(), entry.getValue());}try {pro.store(new FileOutputStream(propertityPath), comment);} catch (Exception e) {System.err.println("存储properties出错");}}/** * @param map * 将要写入的资源放入该map中 HashMap<String, String> * @param comment * 对在资源文件的描述 * @param propertityPath * 资源文件要存放的路径例如H:/mysql.xml */public static void createPropertityXMLFile(String propertityPath, String comment, Map<String, String> map) {File file = new File(propertityPath);new File(file.getParent()).mkdirs();Properties pro = new Properties();for (Map.Entry<String, String> entry : map.entrySet()) {pro.setProperty(entry.getKey(), entry.getValue());}try {pro.storeToXML(new FileOutputStream(propertityPath), comment,"utf-8");} catch (Exception e) {System.err.println("存储properties出错");}}/** * * @param filePath "H:/mysql.properties" * @return Properties的实例对象 */public static Properties loadProperties(String filePath){Properties pro=new Properties();try {pro.load(new FileInputStream(new File(filePath)));} catch (FileNotFoundException e) {System.err.println("文件未找到");e.printStackTrace();} catch (IOException e) {e.printStackTrace();}return pro;}/** * * @param filePath "H:/mysql.xml" * @return Properties的实例对象 */public static Properties loadXMLProperties(String filePath){Properties pro=new Properties();try {pro.loadFromXML(new FileInputStream(new File(filePath)));} catch (FileNotFoundException e) {System.err.println("文件未找到");e.printStackTrace();} catch (IOException e) {e.printStackTrace();}return pro;}/** * @param args */public static void main(String[] args) {Map<String, String> map = new HashMap<String, String>();map.put("a", "value1");map.put("b", "value2");map.put("c", "value3");String path="H:" + File.separator + "a//a/"+File.separator;createPropertityFile(path+"mysql.properties", "mysql数据库资源配置",map);createPropertityXMLFile(path+"mysql.xml", "mysql数据库资源配置",map);Properties pro=loadProperties(path+"mysql.properties");System.out.println(pro);pro=loadXMLProperties(path+"mysql.xml");System.out.println(pro);}}
0 0
- Properties资源文件工具类
- properties 资源文件解析工具
- properties文件工具类
- Properties文件读取工具类
- 获取properties文件工具类
- 读取properties文件,工具类。
- 加载properties文件工具类
- 工具类: Properties文件载入
- Properties文件读取工具类
- Properties文件读取工具类
- Properties文件载入工具类
- Properties文件载入工具类
- 读取properties文件工具类
- properties文件读取工具类
- 资源文件工具类
- properties资源文件总结
- 读取properties资源文件
- Properties读写资源文件
- 100天坚持行动---相约4月19号
- sudo
- 存储properties资源文件
- rj45接口定义/rj45针脚定义/rj45引脚定义
- 【IOS学习】之九、Blocks的实现续
- Properties资源文件工具类
- 自定义Annotation
- iOS json字符串转化为NSArray(解析)
- 一个bug
- 【IOS学习】之九、Blocks的实现再续
- HDU解题报告--1004
- A^B
- UVa 10194 足球
- 使用FileUtils简化你的文件操作