package com.daiyu;
import java.io.InputStream;
import java.lang.reflect.Method;
import java.util.Properties;
import java.util.Set;
/**
*
**/
public class A {
public static void main(String[] args) throws Exception{
//1.将conf.properties文件中的信息存到properties集合中
Properties p = new Properties();
InputStream inputStream = ClassLoader.getSystemClassLoader().getResourceAsStream("com/daiyu/conf.properties");
p.load(inputStream);
String className = p.getProperty("className");
Class aClass = Class.forName(className);
Object o = aClass.newInstance();
Set<String> set = p.stringPropertyNames();
for (String key : set) {
String substring = "set"+key.substring(0,1).toUpperCase()+key.substring(1);
try {
Method method = aClass.getMethod(substring,String.class);
method.invoke(o,p.getProperty(key));
} catch (NoSuchMethodException e) {
//e.printStackTrace();
}
}
System.out.println("通过配置文件创建了对象,并赋值结果是:"+o);
}
}
#className=com.daiyu.Person
className=com.daiyu.User
username=zs
password=abc
name=ls
age=18
public class Person {
private String name;
private String age;
@Override
public String toString() {
return "Person{" +
"name='" + name + '\'' +
", age=" + age +
'}';
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getAge() {
return age;
}
public void setAge(String age) {
this.age = age;
}
}
public class User {
private String username;
private String password;
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
@Override
public String toString() {
return "User{" +
"username='" + username + '\'' +
", password='" + password + '\'' +
'}';
}
}
请问String substring = "set"+key.substring(0,1).toUpperCase()+key.substring(1);什么意思