properties读取配置文件(配置白名单的时候)
2016-04-05 16:51
363 查看
代码说明:为了支持中文,需要使用new InputStreamReader(new FileInputStream(filePath),"utf-8")控制中文的格式 package com.my; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.util.Properties; public class Main { public static void main(String[] args) { try { String path = Main.class.getResource("/").getPath()+"/files/test.properties"; GetAllProperties(path); } catch (Exception e) { e.printStackTrace(); } } public static void GetAllProperties(String filePath) throws IOException { Properties pps = new Properties(); //用inputStreanReader设置中文编码 InputStreamReader is = new InputStreamReader(new FileInputStream(filePath),"utf-8"); pps.load(is); Object pwd = pps.get("db.main.password"); Object name = pps.get("db.main.username"); Object driver = pps.get("db.main.driver"); is.close(); System.out.println("密码:"+pwd+"\n"+"名字:"+name+"\n"+"驱动:"+driver); } }
相关文章推荐
- sqoop参数类型影响
- Probe监控Tomcat
- Linux NFS服务器的安装与配置
- 《LInux内核分析》第七周作业:Linux内核如何装载和启动一个可执行程序
- arm-linux内存管理学习笔记(1)-内存页表的硬件原理
- LOOPS(HDU3853)
- 一个popen异步的例子
- idea tomcat 热部署
- 阿里云主机windows系统Apache启用浏览器缓存的方法
- Linux内核分析第三章读书笔记
- CentOS 6.3下配置软RAID(Software RAID)
- 从一道面试题谈linux下fork的运行机制
- Linux Performance Tunnel
- linux命令--tar
- 在shell脚本中以其他用户身份执行命令
- linux中fork()函数详解
- CentOS6.5编译安装Nginx和Openssl
- linux下C与C++混合编程
- ubuntu 14.04 安装opencv 3.1(包括contrib库)
- linux下安装nginx(转载)