package com.ruoyi.platform.utils;

import org.yaml.snakeyaml.Yaml;

import java.io.FileWriter;
import java.io.IOException;
import java.util.Map;

public class YamlUtils {

    /**
     * 将Map对象转换为YAML格式并写入指定路径的文件中
     *
     * @param data      Map对象
     * @param path      文件路径
     * @param fileName  文件名
     */
    public static void generateYamlFile(Map<String, Object> data, String path, String fileName) {
        Yaml yaml = new Yaml();
        String fullPath = path + "/" + fileName + ".yaml";

        try (FileWriter writer = new FileWriter(fullPath)) {
            yaml.dump(data, writer);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
