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<Object> keyValue =prop.keySet();
for(Iterator<Object> 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;
}