加载属性文件Properties
2019-03-17 14:24
267 查看
版权声明:本文为博主原创文章,遵循 CC 4.0 by-sa 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/weixin_44428051/article/details/88618898
package com.sico;
import java.io.*;
import java.util.Properties;
/**
-
ClassLoader用于读取配置文件的信息,配置文件放在classes下
*/
@SuppressWarnings(“unused”)
public class ConfigUtils {private static Properties prop = null;
static {
try { InputStream ins = ConfigUtils.class.getClassLoader().getResourceAsStream("nettyConfig.properties"); BufferedReader br = new BufferedReader(new InputStreamReader(ins)); prop = new Properties(); prop.load(br); } catch (IOException e) { e.printStackTrace(); }
}
public static Integer getClientPort() {
Integer clientPort = Integer.valueOf((String) prop.get(“client.port”));
return clientPort;
}public static Integer getServerPort() {
Integer serverPort = Integer.valueOf((String) prop.get(“server.port”));
return serverPort;
}public static String getClientUrl() {
String clientUrl = (String) prop.get(“client.url”);
return clientUrl;
}public static void main(String[] args) {
String clientUrl = getClientUrl();
System.out.println(“clientUrl:”+clientUrl);
}
}
相关文章推荐
- spring加载properties属性文件到内存
- java中使用Properties加载XML文件设置java窗体应用程序的窗体属性
- java web项目启动加载properties属性文件
- 自定义监听器类来加载web.xml中的<context-param>系统属性</context-param> 和xxx.properties文件属性
- Java 反射将配置文件数据加载到对象属性中Reflect与Properties使用
- LoadProperties:加载属性文件
- jeesite.properties属性文件为utf-8格式时的加载修改
- 练习 2017-08-15 属性(Properties)类加载资源文件
- 利用Java注解特性加载属性文件(properties)的值到Java类
- IDEA spring的xml配置文件加载不到properties属性问题
- 加载properties文件属性的Java工具类实现
- 关于加载Spring加载外部文件属性.properties的问题
- spring+mybatis 注入properties文件中属性失败导致datasource加载失败的原因和解决
- java 加载properties配置文件属性到常量
- spring加载properties属性文件到内存
- JAVA六种加载属性文件(Properties file )的方法
- spring加载配置属性文件(properties)
- Spring加载properties文件的属性的值
- 如何使用java类来加载properties配置文件的属性信息
- spring的属性加载器,加载properties文件中的属性