没事写的,实际更加推荐使用网上一些更加完善的在线工具
效果
正向转换
原内容

转换结果

反向
原内容

结果

主要类
public class p2y {
private static final String REVERSE = "-r";
private static final Pattern PATTERN = Pattern.compile("(.+)\\[(\\d+)]$");
public static void main(String[] args) throws IOException {
args = new String[]{
"src/p2y/test.yaml","-r"};
if (args.length == 1) {
handleP2y(args[0]);
} else if (args.length == 2) {
if (args[1].equals(REVERSE)) {
handleY2p(args[0]);
} else {
printHelp();
}
} else {
printHelp();
}
}
private static void handleY2p(String path) throws IOException {
List<String> lines = Files.readAllLines(Paths.get(path), Charset.forName("UTF-8"));
LinkedList<State> stack = new LinkedList<>();
for (String line : lines) {
handleLine(stack, line);
}
}
private static void handleLine(LinkedList<State> stack, String line) {
int index;
String name;
String value;
for (int i = 0; i < line.length(); i++) {
char c = line.charAt(i);
switch (c) {
case ' ':
case '\t':
break;
case '#':
System.out.println(line);
return;
case '-':
stack.peekLast().index++;
index = line

本文介绍了一个简单的命令行工具,用于实现属性文件(prop)与YAML文件之间的相互转换。该工具通过解析文件内容并按指定格式输出,支持通过控制台参数指定转换方向,默认为prop转YAML。

6006

被折叠的 条评论
为什么被折叠?



