使用单例读取配置文件
来源:互联网 发布:淘宝diy电脑哪家好 编辑:程序博客网 时间:2024/05/20 00:17
本文旨在整理个人工作总结,仅供参考
直接贴代码,java代码如下:
import java.io.IOException;import java.io.InputStream;import java.util.Properties;/** * @ClassName: WordPropertyUtil * @Description: 读取配置文件 * @author sly.shuai * @date2017年2月22日 上午10:20:20 * @version V1.0 */@SuppressWarnings("serial")public class WordPropertyUtil extends Properties{ private static WordPropertyUtil instance; // 读取配置文件 private WordPropertyUtil() { InputStream iss = null; try { iss = this.getClass().getResourceAsStream("/wordTemplate.properties"); this.load(iss); } catch (IOException e) { } finally { if (iss != null) { try { iss.close(); } catch (IOException e) { } } } } // 单例模式 public static WordPropertyUtil getInstance() { if (instance != null) { return instance; } else { instance = new WordPropertyUtil(); return instance; } }}
配置文件wordTemplate.properties内容如下:
#word导出模板参数配置#银行签收单模板存储位置templatePath = /sly_files_server/word/templatePath/#银行签收单模板名字templateName = test.ftl#生成word的存储位置filePath = /sly_files_server/word/filePath/#生成word的名字fileName = test.doc
具体调用方式如下:
String templatePath = WordPropertyUtil.getInstance().getProperty("templatePath");String templateName = WordPropertyUtil.getInstance().getProperty("templateName");String filePath = WordPropertyUtil.getInstance().getProperty("filePath");String fileName = WordPropertyUtil.getInstance().getProperty("fileName");
1 0
- 使用单例读取配置文件
- java单例读取配置文件
- JDOM读取XML配置文件--单例模式
- Java单例模式实例---读取配置文件
- Java单例模式实例---读取配置文件
- JAVA单例模式读取properties配置文件
- 单例模式之读取配置文件
- 单例模式读取配置文件到内存中
- 配置文件读取类conf.class.php 单例模式应用
- 基于单例模式的配置文件读取方法
- 使用单例模式加载配置文件
- 使用rapidxml读取配置文件
- 使用ResourceBundle读取配置文件
- 配置文件读取的使用
- 使用ResourceBundle读取配置文件
- 使用PropertyPlaceholderConfigurer读取配置文件
- 使用properties读取配置文件
- 使用单例模式读取Properties文件
- MySQL宽字节注入漏洞分析
- 锚点设置距离顶部高度的方法
- JavaScript 深浅拷贝
- as svn更新不了代码,并且svn checkout时报错Unable to connect to a repository at URL
- myeclipse当中,如何导入或者导出项目
- 使用单例读取配置文件
- HTTP Live Streaming直播(iOS直播)技术分析与实现
- jquery学习笔记二(应用方法)
- Git大文件存储 git-lfs
- thinkphp 3.1模板中的xss漏洞修复
- sqlyog导出excel乱码问题解决方法
- HTML+CSS——初学笔记(二)
- Android 实现沉浸式(Translucent Bars)
- Linux Nginx的安装,信号控制,日志