zoukankan      html  css  js  c++  java
  • 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");
    	}
    
    }
    
  • 相关阅读:
    vfpConn
    OAuth2.0
    开源日志组件ELMAH
    c# 动态数组 ArrayList
    OleDbHelper类
    系统权限管理框架
    Log4net数据表
    C#创建DBF自由库
    数字化校园passport
    使用 StateServer 保存 Session 解决 Session过期,登陆过期问题。
  • 原文地址:https://www.cnblogs.com/zhangfei/p/4505714.html
Copyright © 2011-2022 走看看