public class MainClass {
public static void main(String[] args) throws IOException,
IntrospectionException, IllegalArgumentException,
IllegalAccessException, InvocationTargetException {
String userInfo = "userID=12,userName='Zhaomin'";
String[] s = userInfo.split(",");
BufferedWriter bw = new BufferedWriter(new FileWriter(
"E:/heima/src/property/userInfo.properties"));
for (String str : s) {
bw.write(str);
bw.newLine();
bw.flush();
}
bw.close();
BufferedReader br = new BufferedReader(new FileReader(
"E:/heima/src/property/userInfo.properties"));
Properties pro = new Properties();
pro.load(br);
Set<Object> set = pro.keySet();
UserInfo ui = new UserInfo();
for (Object o : set) {
String key = (String) o;
String value = pro.getProperty(key);
PropertyDescriptor pd = new PropertyDescriptor(key, ui.getClass());
if(pd.getPropertyType().equals(int.class)){
int value1 = Integer.parseInt(value);
Method m = pd.getWriteMethod();
m.invoke(ui,value1);
}
if(pd.getPropertyType().equals(String.class)){
Method m = pd.getWriteMethod();
m.invoke(ui,value);
}