properties 文件解析
1.提供properties文件
jdbc.driver=com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql://localhost:3306/future?useUnicode=true&characterEncoding=utf-8
jdbc.username=root
jdbc.password=root
2.properties文件解析方法实现
package cn.xiaobing.util; import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties; public class PropertiesDemo01 {
/**
* 读取解析properties文件
*/
public static void readProperties() {
//java.util包下专门做properties文件解析的类=》Properties
Properties properties = new Properties();
File file = new File("src/test/resources/jdbc.properties");
//判断文件是否存在
if(file.exists()) {
InputStream inStream = null;
try {
inStream = new FileInputStream(file);
//通过调用Properties的load方法,实现文件的加载、解析
properties.load(inStream);
} catch (Exception e) {
e.printStackTrace();
}finally {
if(inStream != null) {
try {
inStream.close();//关闭流
} catch (IOException e) {
e.printStackTrace();
}
}
}
String url = properties.getProperty("jdbc.url");
System.out.println("url:"+url);
System.out.println("username:"+properties.getProperty("jdbc.username"));
System.out.println("password:"+properties.getProperty("jdbc.password"));
}else {
System.out.println("properties文件未找到,请核对提供文件路径!");
}
}
public static void main(String[] args) {
readProperties();
}
}
3.执行输出


4.总结,不足之处后续修改补充!
properties 文件解析的更多相关文章
- Quartz的Properties文件解析
将可变信息放在properties文件是使配置更加灵活. 1.文档位置和加载顺序 1. StdSchedulerFactory默认加载quartz包下的quartz.properties文件,如果我们 ...
- nodejs版实现properties后缀文件解析
1.propertiesParser.js let readline = require('readline'); let fs = require('fs'); // properties文件路径 ...
- properties文件中中文不能显示或者中文乱码
1.properties 文件中文乱码问题 鼠标“右击”文件 => Resource => Text file encoding => UTF-8 2.properties 文件解析 ...
- java解析properties文件
在自动化测试过程中,经常会有一些公用的属性要配置,以便后面给脚本使用,我们可以选择xml, excel或者json格式来存贮这些数据,但其实java本身就提供了properties类来处理proper ...
- 【Spring源码分析】.properties文件读取及占位符${...}替换源码解析
前言 我们在开发中常遇到一种场景,Bean里面有一些参数是比较固定的,这种时候通常会采用配置的方式,将这些参数配置在.properties文件中,然后在Bean实例化的时候通过Spring将这些.pr ...
- 【Java】Properties文件的解析
public abstract class ReadProperties { public ReadProperties() {} /** * 回调函数,由调用者处理 * @param key * @ ...
- Spring系列之——springboot解析resources.application.properties文件
摘要:本文通过讲解如何解析application.properties属性,介绍了几个注解的运用@Value @ConfigurationProperties @EnableConfiguration ...
- Python:解析properties文件
在项目中遇到解析properties的情况,而Python中正好没有解析properties文件的现成模块,于是从网上找到了这个脚本,有一些小地方修改了一下 原博客: Python读写properti ...
- maven 项目打包时无法解析读取properties文件
在做项目时遇见一个问题,无法解析properties文件的 内容 异常为 Could not resolve placeholder ......... 在此之前均有做相关的 配置 但是从未出现过如上 ...
随机推荐
- Spirit带你了解CSS各个方向的居中方案
水平居中和垂直居中的方案 先看HTML的骨架 后面的代码都是基于这个来写的 <!DOCTYPE html> <html lang="en"> <hea ...
- git pull 时remote: HTTP Basic: Access denied解决方案
当qian windows用户密码过期更改了密码后,操作git pull 拉取远程仓库代码或git push时报错 如下:remote: HTTP Basic: Access denied Auth ...
- P4100-[HEOI2013]钙铁锌硒维生素【矩阵求逆,最大匹配】
正题 题目链接:https://www.luogu.com.cn/problem/P4100 题目大意 给出\(n\)个线性无关的向量\(A_i\),然后给出\(n\)个向量\(B_i\),求一个字典 ...
- CF235D-Graph Game【LCA,数学期望】
正题 题目链接:https://www.luogu.com.cn/problem/CF235D 题目大意 给出一棵基环树,每次随机选择一个点让权值加上这个点的连通块大小然后删掉这个点. 求删光所有点时 ...
- 一款简单实用的串口通讯框架(SerialIo)
前言 大龄程序员失业状态,前几天面试了一家与医疗设备为主的公司并录取:因该单位涉及串口通讯方面技术,自己曾做过通讯相关的一些项目,涉及Socket的较多,也使用SuperSocket做过一些项目,入职 ...
- 感恩笔记之SQL查询功能最简使用模板
感恩笔记之SQL查询功能最简使用模板 第一部分:SQL单表功能 1 语句主要关键字 SELECT --查询数据列 INTO --新建数据表 FROM --查询数据表 WHERE --筛选数据表结果 O ...
- 数值计算:Legendre多项式
Legendre多项式的概念以及正交特性在此不多作描述,可以参考数学物理方程相关教材,本文主要讨论在数值计算中对于Legendre多项式以及其导数的计算方法. Legendre多项式的计算 递推公式 ...
- 开发函数计算的正确姿势——OCR 服务
作者 | 杜万(倚贤) 阿里云技术专家 简介 首先介绍下在本文出现的几个比较重要的概念: OCR(光学字符识别):光学字符识别(Optical Character Recognition, OCR)是 ...
- SudokuSolver 1.0:用C++实现的数独解题程序 【二】
本篇是 SudokuSolver 1.0:用C++实现的数独解题程序 [一] 的续篇. CQuizDealer::loadQuiz 接口实现 1 CQuizDealer* CQuizDealer::s ...
- 3 Implementation: The Big Picture 实现:蓝图
三.Implementation: The Big Picture 实现:蓝图 3.1 Layering of a .NET Solution .Net解决方案的分层 The picture belo ...