调用:

Configure.getValue("discount.strategy.class");

  

配置类:

package com.util;

import com.sun.javafx.fxml.PropertyNotFoundException;

import java.io.InputStream;
import java.util.Properties; public class Configure { private static Properties config; static {
System.out.println("初始化加载配置!"); String filePath = "application.properties"; config = new Properties();
try {
ClassLoader CL = Configure.class.getClassLoader();
InputStream in;
if (CL != null) {
in = CL.getResourceAsStream(filePath);
} else {
in = ClassLoader.getSystemResourceAsStream(filePath);
}
config.load(in);
in.close();
} catch (Exception e) {
throw new PropertyNotFoundException("服务器配置信息读取错误:" + e.getMessage());
}
} public static String getValue(String key) {
if (config.containsKey(key)) {
String value = config.getProperty(key);
return value;
} else {
return "";
}
} public static int getValueInt(String key) {
String value = getValue(key);
int valueInt = 0;
try {
valueInt = Integer.parseInt(value);
} catch (NumberFormatException e) {
e.printStackTrace();
return valueInt;
}
return valueInt;
}
}

  

读取 classes下的配置文件的更多相关文章

  1. Spring Junit 读取WEB-INF下的配置文件

    假设Spring配置文件为applicationContext.xml 一.Spring配置文件在类路径下面 在Spring的java应用程序中,一般我们的Spring的配置文件都是放在放在类路径下面 ...

  2. java 读取src下的配置文件

    很多时候,我们都将配置文件放在eclipse的src目录下,这个位置,相当于,当导出可执行jar包后,配置文件放在和jar同级的目录中,比如jar包放在/opt目录下,则配置文件放在/opt下,则ja ...

  3. maven工程读取resource下配置文件

    maven工程读取resource下配置文件 在maven工程中,我们会将配置文件放到,src/main/resources   下面,例如 我们需要确认resource 下的文件 编译之后存放的位置 ...

  4. Maven项目中读取src/main/resources目录下的配置文件

    在Maven项目的开发中,当需要读取src/下的配置文件时,该怎么做? 我们假设Resources下有一个文件名为kafka.properties的配置文件(为什么用kafka.properties, ...

  5. 解决:java 读取 resources 下面的 json 文件

    前言:java 读取 工程下的配置文件,文件类型为 json(*.json),记录一下始终读取不到 json 文件的坑.maven项目 直接上工具类代码 package com.yule.compon ...

  6. java读取resource目录下的配置文件

    java读取resource目录下的配置文件 1:配置resource目录 下的文件 host: 127.0.0.1 port: 9300 2:读取    / 代表resource目录 InputSt ...

  7. Java读取Maven工程下的配置文件,工具类

    Java开发中,经常需要在maven工程中读取src/main/resources下的配置文件: 思路如下: Class.getClassLoader() 返回类加载器ClassLoader,进而可以 ...

  8. JAVA Web项目获取src和WebContent目录下的配置文件

    一,获取src下面的配置文件信息 1,结构图如下: package com.binp.properties; import java.io.FileInputStream; import java.i ...

  9. m_Orchestrate learning system---二十九、什么情况下用数据库做配置字段,什么情况下用配置文件做配置

    m_Orchestrate learning system---二十九.什么情况下用数据库做配置字段,什么情况下用配置文件做配置 一.总结 一句话总结: 配置文件 开发人员 重置 数据库 非开发人员 ...

随机推荐

  1. SonarQube学习入门指南

    1. 什么是SonarQube? SonarQube 官网:https://www.sonarqube.org/ SonarQube®是一种自动代码审查工具,用于检测代码中的错误,漏洞和代码异味.它可 ...

  2. [svc]centos6使用chkconfig治理服务和其原理

    centos6开机启动级别 $ cat /etc/inittab ... # 0 - halt (Do NOT set initdefault to this) # 1 - Single user m ...

  3. extern C的作用具体解释

    转载于:http://www.cnblogs.com/rollenholt/archive/2012/03/20/2409046.html 1.引言 C++语言的创建初衷是"a better ...

  4. 关于chrome的开发调试方式

    chrome://inspect/#devices 调试移动设备app chrome://version 查看chrome浏览器版本信息 chrome://components/ 查看组件信息 上面的 ...

  5. distinct aggregation

    https://docs.google.com/document/d/1zj6OA-K2hi7ah8Fo-xTQB-mVmYfm6LsN2_NHgTCVmJI/edit# https://issues ...

  6. my stackoverflow

    https://stackoverflow.com/questions/48017641/how-to-monitor-elastic-stack-without-x-pack https://sta ...

  7. TimescaleDB比拼InfluxDB:如何选择合适的时序数据库?

    https://www.itcodemonkey.com/article/9339.html 时序数据已用于越来越多的应用中,包括物联网.DevOps.金融.零售.物流.石油天然气.制造业.汽车.太空 ...

  8. numpy数组-截取部分

    import numpy as np a = np.array([1,2,3,4,5]) slice = a[:3] slice[0] = 100 print(a) # 结果 [100,2,3,4,5 ...

  9. Sql Server 2008 清除日志

    --在SQL2008中清除日志就必须在简单模式下进行,等清除动作完毕再调回到完全模式. USE [master] GO ALTER DATABASE SSCDZ SET RECOVERY SIMPLE ...

  10. 【ActiveMQ】Spring Jms集成ActiveMQ学习记录

    Spring Jms集成ActiveMQ学习记录. 引入依赖包 无论生产者还是消费者均引入这些包: <properties> <spring.version>3.0.5.REL ...