YAML中重复的KEY的判断
package com.test.util;
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
public class CheckYaml {
public void checkYaml(String fileName) {
BufferedReader read = null;
try {
read = new BufferedReader(new InputStreamReader(new FileInputStream("locator/" + fileName)));
String temp = read.readLine();
List<String> list = new ArrayList<String>();
while(temp != null){
if(!temp.startsWith(" ") && !temp.trim().startsWith("#")){
String key = temp.substring(0, temp.length()-1);
if(list.contains(key)){
System.out.println("duplicate key: "+key);
}else{
list.add(key);
}
}
temp = read.readLine();
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}finally{
try {
if(read != null){
read.close();
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
public static void main(String[] args) {
CheckYaml cy = new CheckYaml();
cy.checkYaml("TestBaidu.yaml");
}
}
点亮测试人生!QQ:408129370
百度阅读电子书地址:http://yuedu.baidu.com/ebook/f6dbb2a2f01dc281e53af0f3
讨论QQ群:536192476
个人公众号:
百度阅读电子书地址:http://yuedu.baidu.com/ebook/f6dbb2a2f01dc281e53af0f3
讨论QQ群:536192476
个人公众号:
浙公网安备 33010602011771号