| | |
| | | @Component |
| | | public class YamlUtils { |
| | | |
| | | private static final String src = "src/main/resources/application-prod.yml"; |
| | | private final static String C = "#"; |
| | | private final static String CHARSET = "UTF-8"; |
| | | //读取后的每行数据 |
| | | private static List<String> LINES = null; |
| | | @Autowired |
| | | private DataResourceService dataResourceService; |
| | | |
| | | private static final String src = "src/main/resources/application-prod.yml"; |
| | | public static void main(String[] args) { |
| | | Map<String, Integer> keyCountMap = new HashMap<>(); |
| | | try { |
| | | List<String> lines = FileUtils.readLines(new File(src), CHARSET); |
| | | for (int i = 0; i < lines.size(); i++) { |
| | | String line = lines.get(i); |
| | | if (line.contains(C)) { |
| | | String[] split = line.split(C); |
| | | String tmp = split[0]; |
| | | String memo = split[1];//获取注释 |
| | | |
| | | private final static String C = "#"; |
| | | private final static String CHARSET = "UTF-8"; |
| | | String[] split1 = tmp.split(":"); |
| | | String name = split1[0]; |
| | | String data = split1[1]; |
| | | System.out.println(memo); |
| | | System.out.println(name); |
| | | System.out.println(data); |
| | | } |
| | | } |
| | | |
| | | //读取后的每行数据 |
| | | private static List<String> LINES = null; |
| | | } catch (IOException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | |
| | | public Map<String, Object> read() { |
| | | Yaml yaml = new Yaml(); |
| | |
| | | dataResource.setData(null); |
| | | } else if (value instanceof Map) { |
| | | dataResource.setData(JSON.toJSONString(value)); |
| | | }else { |
| | | } else { |
| | | dataResource.setData(value.toString()); |
| | | } |
| | | dataResource.setCreateTime(new Date()); |
| | |
| | | data = ""; |
| | | } |
| | | map.put(dataResource.getName(), data); |
| | | } |
| | | } |
| | | |
| | | public static void main(String[] args) { |
| | | Map<String, Integer> keyCountMap = new HashMap<>(); |
| | | try { |
| | | List<String> lines = FileUtils.readLines(new File(src), CHARSET); |
| | | for (int i = 0; i < lines.size(); i++) { |
| | | String line = lines.get(i); |
| | | if (line.contains(C)) { |
| | | String[] split = line.split(C); |
| | | String tmp = split[0]; |
| | | String memo = split[1];//获取注释 |
| | | |
| | | String[] split1 = tmp.split(":"); |
| | | String name = split1[0]; |
| | | String data = split1[1]; |
| | | System.out.println(memo); |
| | | System.out.println(name); |
| | | System.out.println(data); |
| | | } |
| | | } |
| | | |
| | | } catch (IOException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | |