• java 读取外部和source下配置文件


    import java.io.File;
    import java.io.FileInputStream;
    import java.net.URL;
    import java.util.Map;
    
    import org.bouncycastle.crypto.RuntimeCryptoException;
    import org.yaml.snakeyaml.Yaml;
    
    
    
    
    public class DbpTestConfig {
        private static String dbpIP;
        
        private static String dbpPort;
        
        private static String testServerIP;
        
        private static String testServerPort;
       
        static{
            Yaml yaml = new Yaml();
            try {
            //读取当前项目同级目录下的配置文件,jar包形式 File dumpFile
    =new File(System.getProperty("user.dir") + "/application.yml"); if(!dumpFile.exists()){
              //读取source目录下配置文件 URL url
    = DbpTestConfig.class.getClassLoader().getResource("application.yml"); if(url==null){ throw new RuntimeException("not found application.yml"); } dumpFile=new File(url.getPath()); } Map map =(Map)yaml.load(new FileInputStream(dumpFile)); Map<String,String> paramMap =(Map) map.get("dbptest"); if(paramMap==null){ throw new RuntimeException("not found parameter dbptest"); } dbpIP=paramMap.get("dbpIP"); dbpPort=String.valueOf(paramMap.get("dbpPort")); testServerIP=paramMap.get("testServerIP"); testServerPort=String.valueOf(paramMap.get("testServerPort")); } catch (Exception e1) { // TODO Auto-generated catch block e1.printStackTrace(); } } public static String getDbpIP() { return dbpIP; } public static String getDbpPort() { return dbpPort; } public static String getTestServerIP() { return testServerIP; } public static String getTestServerPort() { return testServerPort; } }
  • 相关阅读:
    My Houdini First Step
    MaxScript随机赋材质
    Groups of Operators
    Select groups in scene
    投篮球
    U3D PlayMovie
    unicornForest
    MaxScript Spinner/progressBar
    MaxScript Button
    MaxScript 扇子打开
  • 原文地址:https://www.cnblogs.com/itniwota/p/9320049.html
Copyright © 2020-2023  润新知