import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties; public class Main {
private static Main main = new Main();
private Main(){}
public static Main getMain() {
return main;
}
public static Properties prop = null;
// 静态加载配置文件
static {
prop = new Properties();
ClassLoader classLoader = Main.class.getClassLoader();
InputStream inputStream = classLoader.getResourceAsStream("config.properties");
try {
prop.load(inputStream);
} catch (IOException e) {
e.printStackTrace();
}
}
// 给properties中设置值
public static void modifyConfig(String key, String value) {
try {
// 从输入流中读取属性列表(键和元素对)
prop.setProperty(key, value);
String path = Main.class.getResource("/config.properties").getPath();
FileOutputStream outputFile = new FileOutputStream(path);
prop.store(outputFile, "modify");
outputFile.close();
outputFile.flush();
} catch (Exception e) {
e.printStackTrace();
}
}
// 通过key获取值
public static String getValueByKey(String key) {
if(prop.get(key)!=null) {
return (String) prop.get(key);
}
return null;
}
}

最新文章

  1. 【maven】maven创建web项目-pom文件提示web.xml is missing and <failOnMissingWebXml> is set to true
  2. C++学习笔记 知识集锦(二)
  3. 删除Management Data Warehouse (MDW) job失败
  4. LeetCode Restore IP Addresses
  5. JavaWeb---总结(九)通过Servlet生成验证码图片
  6. Qt之QFileSystemWatcher
  7. systemstate dump 介绍
  8. Views
  9. ext 金额大写
  10. 1:环境安装与介绍:canopy
  11. 我们在 web 应用开发过程中经常遇到输出某种编码的字 符, 如 iso8859-1 等, 如何输出一个某种编码的字符串?
  12. hdu4707 Pet
  13. 【BZOJ 2395】Time is money
  14. LFYZ-OJ ID: 1021 邮票问题
  15. IP池验证IP是否可用 及scrapy使用 ip池
  16. C#工具类:使用SharpZipLib进行压缩、解压文件
  17. Python全栈开发之路 【第十七篇】:jQuery的位置属性、事件及案例
  18. docker lamp
  19. Facebook的一些基本操作(网页版)
  20. Can't create handler inside thread that has not called Looper.prepare()

热门文章

  1. 「Goravel 上新」验证表单的三种新姿势,估计你只用过一种
  2. Java基础篇——垃圾收集详解
  3. C++string与int的相互转换(使用C++11)
  4. runtime-第一篇
  5. AI换脸实战教学(FaceSwap的使用)---------第二步Tools:处理输入数据集。
  6. Unity自定义Button
  7. C# 如何部分加载“超大”解决方案中的部分项目
  8. 重学SpringBoot. step2 Spring AOP
  9. spring cloud alibaba - Nacos 作为注册中心基础使用-服务提供者和消费者
  10. 模型预处理层介绍(1) - Discretization