publicclass TestStudent {
public static void main(String[] args)throws Exception, Exception {
Scanner sc=new Scanner(System.in);
System.out.println("请输入学生的信息(姓名:年龄:成绩):");
String s=sc.nextLine();
//用冒号分隔开
String[] ss = s.split(":");
//存放分隔后的数据
Properties p=new Properties();
File f=newFile("student.properties");
if(!f.exists()){
p.load(new FileInputStream(f));
}
//设置p的属性name值为ss[0]
p.setProperty("name", ss[0]);
//设置p的属性age值为ss[1]
p.setProperty("age", ss[1]);
//设置p的属性score值为ss[2]
p.setProperty("score", ss[2]);
//把得到的p的值存储到刷新后的.properties文件里
p.store(new FileOutputStream(f),"student.properties");
//找到需要反射的类放到定义的Class中
使用反射机制完成学生对象的创建并输出学生信息。
最新推荐文章于 2023-04-24 18:21:44 发布