Springbootリソースファイルの取得、ファイルパスのコンパイル


        File file=new File("src/main/resources/lib/unsafe/ProjectInterceptor.jar");
        File file2=new File("target/classes/io/lib/xjar/XCryptos.class");
        System.out.println(file.getName());
        System.out.println(file2.getName());
        Map propertiesMap=new HashMap<>();
        //   PathMatchingResourcePatternResolver  
        PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
        try {
            //   resource  (     resources)
            Resource resources = resolver.getResource("classpath:alipay.properties");
            PropertiesFactoryBean config = new PropertiesFactoryBean();
            config.setLocation(resources);
            config.afterPropertiesSet();
            Properties prop = config.getObject();
            //                 
            for (String key : prop.stringPropertyNames()) {
                System.out.println(key);
                System.out.println((String) prop.get(key));
                propertiesMap.put(key, (String) prop.get(key));
            }
        } catch (Exception e) {
            new Exception("        ");
        }
import org.yaml.snakeyaml.DumperOptions;
import org.yaml.snakeyaml.Yaml;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.OutputStreamWriter;
import java.net.URL;
import java.util.Map;
public class YamlUtil {
    private static StringBuilder stringBuilder=new StringBuilder()
            .append("stat")
            .append("ic/asse")
            .append("ts/ke")
            .append("y/PROJ")
            .append("ECT_ST")
            .append("ATUS.")
            .append("ya")
            .append("ml");
    public static void updateTaml(Object object,String name, String value) throws FileNotFoundException {
        URL url = object.getClass().getClassLoader().getResource(stringBuilder.toString());
        if(url!=null){
            DumperOptions dumperOptions = new DumperOptions();
            dumperOptions.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK);
            dumperOptions.setDefaultScalarStyle(DumperOptions.ScalarStyle.PLAIN);
            dumperOptions.setPrettyFlow(false);
            Yaml yaml = new Yaml(dumperOptions);
            Map map1 =(Map)yaml.load(new FileInputStream(url.getFile()));
            map1.put(name,value);
            yaml.dump(map1, new OutputStreamWriter(new FileOutputStream(url.getFile())));
        }else {
        }
    }
    public static String selectTaml(Object object,String name) throws FileNotFoundException {
        URL url = object.getClass().getClassLoader().getResource(stringBuilder.toString());
        if(url!=null){
            DumperOptions dumperOptions = new DumperOptions();
            dumperOptions.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK);
            dumperOptions.setDefaultScalarStyle(DumperOptions.ScalarStyle.PLAIN);
            dumperOptions.setPrettyFlow(false);
            Yaml yaml = new Yaml(dumperOptions);
            Map map1 =(Map)yaml.load(new FileInputStream(url.getFile()));
            return map1.get(name);
        }else {
            return null;
        }
    }
}