一键修改配置文件
import java.io.File;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.IOException;
import java.util.Arrays;
import java.util.Properties;
/**
* @author: rongyu
* @Date: 2018-07-23 14:04:29
*/
public class Main {
/**
* 配置文件,你需要修改的键值对写入进去
*/
private static String domainProperties = "A.properties";
/**
* 添加文件的备注
*/
private static String comments = "rongyu";
private static String projectPath = "E:\\code\\yousesky_hry_code";
public static void main(String[] args) throws IOException {
traverseFolder(projectPath);
}
public static String getMyProperties(String myProperties) {
return Main.class.getResource("/").getPath() + myProperties;
}
public static Properties getProperties(String propertiesPath) throws IOException {
FileReader fileReader = new FileReader(propertiesPath);
Properties properties = new Properties();
properties.load(fileReader);
fileReader.close();
return properties;
}
public static Properties transformation(Properties from, Properties to) {
to.stringPropertyNames().forEach(
x -> {
String value = from.getProperty(x);
if (value != null && !"".equals(value))
to.setProperty(x, value);
}
);
return to;
}
public static void update(String path, String comments) throws IOException {
String myPropertiesPath = getMyProperties(domainProperties);
Properties myProperties = getProperties(myPropertiesPath);
Properties targetProperties = getProperties(path);
Properties transProperties = transformation(myProperties, targetProperties);
transProperties.store(new FileOutputStream(path), comments);
}
public static void traverseFolder(String path) {
File file = new File(path);
if (file.exists()) {
File[] files = file.listFiles();
if (null == files || files.length == 0) {
return;
} else {
Arrays.stream(files).forEach(
x -> {
if (x.isDirectory())
traverseFolder(x.getAbsolutePath());
else {
String name = x.getName();
if (name.contains(".")) {
String substring = name.substring(name.lastIndexOf(".", name.length()));
if (substring.equals(".properties")) {
// TODO 替换文件
System.out.println(x.getAbsolutePath());
try {
update(x.getAbsolutePath(), comments);
} catch (IOException e) {
System.out.println(x.getAbsolutePath() + "修改失败");
e.printStackTrace();
}
}
}
}
}
);
}
} else {
System.out.println("文件不存在!");
}
}
}

低调大师中文资讯倾力打造互联网数据资讯、行业资源、电子商务、移动互联网、网络营销平台。
持续更新报道IT业界、互联网、市场资讯、驱动更新,是最及时权威的产业资讯及硬件资讯报道平台。
转载内容版权归作者及来源网站所有,本站原创内容转载请注明来源。
-
上一篇
ReactNative开发必备ES6知识
引言 现代前端应用通常都会使用ES6进行开发,ReactNative项目同样也会使用ES6进行开发,对于现代前端项目开发来说,掌握ES6成为一件十分必要的事情。对于ES6的学习,通常都会阅读阮一峰的《ECMAScript 6 入门》,以下这本书中开发ReactNative必备的知识点。 ECMAScript 6简介 ECMAScript6(以下简称ES6)是JavaScript语言的下一代标准,它的目标是让JavaScript语言可以用来编写复杂的大型应用程序,成为企业级开发语言。 let和const命令 ES6新增了let命令,用来声明变量,它的用法类似于var,但是所声明的变量,只在let命令所在的代码块内有效。const声明一个只读的常量,一旦声明,常量的值就不能变化。 变量的解构赋值 ES6允许按照一定模式,从数组和对象中提取值,对变量进行赋值,这被称为解构。 函数的扩展 ES6能直接为函数的参数指定默认值 参数默认值可以与解构赋值的默认值,结合起来使用。 通常情况下,定义了默认值的参数,应该是函数的尾参数 指定了默认值以后,函数的length属性,将返回没有指定默认值的参数个...
-
下一篇
python流程控制
python的流程控制day(04) 1.python的缩进 python 中的代码块不是使用{}来控制范围的,必须使用相同数目的行首缩进空格数,建议在每个缩进层次使用单个制表符或两个空格或四个空格, 不能混用. 2.if语句 格式: if 判断条件: 执行语句…… else: 执行语句…… 其中"判断条件"成立时(非零),则执行后面的语句,而执行内容可以多行,以缩进来区分表示同一范围。 else 为可选语句,当需要在条件不成立时执行内容则可以执行相关语句,具体例子如下: # if age > 16 and age < 30 and height > 160 and weight < 100 and sex=='female': # print('表白') elif的效果和其它语言类似,具体例子如下: # score = input('>>>') # score = int(score) # if score>90: # print('成绩优秀') # elif score>=80: # print('良好') # elif sco...
相关文章
文章评论
共有0条评论来说两句吧...
文章二维码
点击排行
推荐阅读
最新文章
- CentOS7编译安装Cmake3.16.3,解决mysql等软件编译问题
- Dcoker安装(在线仓库),最新的服务器搭配容器使用
- MySQL8.0.19开启GTID主从同步CentOS8
- SpringBoot2配置默认Tomcat设置,开启更多高级功能
- Springboot2将连接池hikari替换为druid,体验最强大的数据库连接池
- CentOS8编译安装MySQL8.0.19
- MySQL数据库在高并发下的优化方案
- SpringBoot2整合Thymeleaf,官方推荐html解决方案
- SpringBoot2初体验,简单认识spring boot2并且搭建基础工程
- SpringBoot2编写第一个Controller,响应你的http请求并返回结果