继续学习Properties,做个小小的联系,我们在网络上经常可以见到当你使用某个东西使用超过了次数网页上就会显示,这个使用已经超过使用次数,请注册之后使用,今天模拟
mian函数就不写了
public static void PropertiesRegeister(){
Properties pro=new Properties();
File file=new File("count.ini");//新建一个文件 用来记录用户使用的次数 time=?
if(!file.existes()){//文件不存在就创建
file.createNewFile();
}
FileInputStreamfr=new FileInputStream(file);
pro.load(fr);//结合
String value=pro.getProperty("time");
if(value!=null){ //不等于空的时候 并且time没大于等于5的时候执行
integer time=Integer.parseInt(value);
if(time>=5){
system.out.println("超过使用次数了,请注册,继续使用");
return ;
}
}
count++;//等于空
FileOutputStream fos=new FileOutputStream("file");
pro.setProperty("time",count+"");
pro.store(fos,"");
}