|
|
|
@@ -46,58 +46,12 @@ public class YamlUtils { |
|
|
|
String fullPath = path + "/" + fileName + ".yaml"; |
|
|
|
|
|
|
|
try (FileWriter writer = new FileWriter(fullPath)) { |
|
|
|
String dump = yaml.dump(data); |
|
|
|
|
|
|
|
yaml.dump(data, writer); |
|
|
|
} catch (IOException e) { |
|
|
|
e.printStackTrace(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// public static void generateYamlFile1(Object data, String path, String fileName) { |
|
|
|
// try { |
|
|
|
// YAMLFactory yamlFactory = new YAMLFactory(); |
|
|
|
// yamlFactory.enable(YAMLGenerator.Feature.MINIMIZE_QUOTES); |
|
|
|
// yamlFactory.disable(YAMLGenerator.Feature.WRITE_DOC_START_MARKER); |
|
|
|
//// |
|
|
|
// ObjectMapper objectMapper = new ObjectMapper(yamlFactory); |
|
|
|
//// ObjectMapper objectMapper = new ObjectMapper(); |
|
|
|
// objectMapper.setPropertyNamingStrategy(PropertyNamingStrategies.SNAKE_CASE); |
|
|
|
// String s = objectMapper.writeValueAsString(data); |
|
|
|
// |
|
|
|
// File directory = new File(path); |
|
|
|
// if (!directory.exists()) { |
|
|
|
// boolean isCreated = directory.mkdirs(); |
|
|
|
// if (!isCreated) { |
|
|
|
// throw new RuntimeException("创建路径失败: " + path); |
|
|
|
// } |
|
|
|
// } |
|
|
|
// |
|
|
|
// try { |
|
|
|
// DumperOptions options = new DumperOptions(); |
|
|
|
// options.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK); |
|
|
|
// // 创建Yaml实例 |
|
|
|
// Yaml yaml = new Yaml(options); |
|
|
|
// |
|
|
|
// String fullPath = path + "/" + fileName + ".yaml"; |
|
|
|
// FileWriter writer = new FileWriter(fullPath); |
|
|
|
// |
|
|
|
// yaml.dump(s, writer); |
|
|
|
// } catch (FileNotFoundException e) { |
|
|
|
// e.printStackTrace(); |
|
|
|
// |
|
|
|
// } catch (IOException e) { |
|
|
|
// throw new RuntimeException(e); |
|
|
|
// } |
|
|
|
// |
|
|
|
// |
|
|
|
// } catch (JsonProcessingException e) { |
|
|
|
// throw new RuntimeException(e); |
|
|
|
// } |
|
|
|
// } |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
* 读取YAML文件并将其内容转换为Map<String, Object> |
|
|
|
* |
|
|
|
|