JAVA获取properties文件参数属性值

properties文件样例:


tcurl=http://100.84.88.210:7001/tc

tcuserid=infodba

tcuserpassword=infodba


java代码

public static String[] getConnection() throws IOException(){

        String tcurl="";

        String tcuserid="";

        String tcuserpassword="";

        Properties prop =new Properties();

InputStream in=ClassLoader.class.getResourceAsStream("/****.properties");//这里填properties文件名称,将properties文件放在Src下;

        prop.load(in);

Set keyValue =prop.keySet();

for(Iterator it=keyValue.iterator();it.hasNext;){

String key=(String) it.next();

    if(key.equals("tcurl")){

      tcurl=(String)prop.get(key);

    }else if(key.equals("tcuserid")){

      tcuserid=(String)prop.get(key);

}else if(key.equals("tcuserpassword")){

      tcuserpassword=(String)prop.get(key);

}

}

String[] args=new String[]{tcurl,tcuserid,tcuserpassword};

return args;

}

你可能感兴趣的:(JAVA获取properties文件参数属性值)