properties文件读取工具类
来源:互联网 发布:小红书是什么软件 编辑:程序博客网 时间:2024/06/05 10:02
PropertiesLoader
import java.io.File;import java.io.FileInputStream;import java.io.FileNotFoundException;import java.io.IOException;import java.io.InputStream;import java.net.URI;import java.net.URISyntaxException;import java.util.Properties;import java.util.logging.Logger;/** * properties文件读取工具类 * * @author -- * */public class PropertiesLoader {private static Logger logger = Logger.getLogger("PropertiesLoader");private static Properties configProps = PropertiesLoader.loadProperties("config.properties");/** 日志存放路径 */public static String getLogPath() {return configProps.getProperty("logPath");}/** 爬虫系统访问入口 */public static String getCrawlerUrl() {return configProps.getProperty("crawlerUrl");}public static Properties loadProperties(String filePath) {Properties props = null;if (filePath == null || filePath.equals("")) {logger.warning("that path of properties file is null");return props;}URI rootPath = null;try {rootPath = PropertiesLoader.class.getClassLoader().getResource("").toURI();} catch (URISyntaxException e) {e.printStackTrace();}String path = rootPath.getPath() + filePath;File file = new File(path);if (!file.exists()) {logger.warning("that properties file is not found");return props;}props = new Properties();InputStream is = null;try {is = new FileInputStream(file);props.load(is);} catch (FileNotFoundException e) {logger.warning("that properties file is not found");e.printStackTrace();} catch (IOException e) {logger.warning("that properties file was loading error");e.printStackTrace();} finally {try {is.close();} catch (IOException e) {logger.warning("that fileInputStream of properties was closeing error");e.printStackTrace();}}return props;}}
阅读全文
0 0
- Properties文件读取工具类
- 读取properties文件,工具类。
- Properties文件读取工具类
- Properties文件读取工具类
- 读取properties文件工具类
- properties文件读取工具类
- 读取properties文件的工具类
- java读取Properties文件的工具类
- Properties属性文件载入、读取工具类
- Java工具类--读取Properties文件
- Java读取Properties文件工具类
- Java属性Properties文件读取工具类
- Java工具类--读取Properties文件
- Java读取Properties文件工具类
- java读取properties文件工具类
- Java中Properties文件读取工具类
- 读取Properties文件的工具类
- 读取properties文件的工具类
- SSH框架文件上传+下载
- hibernate多对多关系操作
- Andrew NG 机器学习 笔记-week6-应用机器学习的建议 ( Advice for Applying Machine Learning)
- SDE连接,创建数据集,数据导入以及数据导出
- 二叉树的创建及前序、中序、后序、层序遍历
- properties文件读取工具类
- 解码Base64并展示图片
- wpf ui分析工具 Snoop
- Kylin启动异常:java.lang.outofMemoryError:Requested array size exceeds VM limit
- Java线程池实现原理
- CentOS7中将PythonY.y.y 升级到PythonX.x.x
- Shadowsocks+Chorme+SwitchyOmega配置
- 微信第三方网页关闭当前页面回到微信对话窗口
- Tensorflow深度学习之五:激活函数