package com.huowolf;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Properties;
public class RunCount {
/*
* 用于记录程序的运行次数。
* 如果使用次数已到,那么给出注册提示。
*/
public static void main(String[] args) throws IOException {
Properties prop = new Properties();
File file = new File("count.ini");
if(!file.exists())
file.createNewFile();
FileInputStream fis = new FileInputStream(file);
prop.load(fis);
int count = 0;
String value = prop.getProperty("time");
if(value!=null) {
count = Integer.parseInt(value);
if(count>=5) {
System.out.println("您好,使用次数已到,请注册!");
return;
}
}
count++;
prop.setProperty("time", count+"");
FileOutputStream fos = new FileOutputStream(file);
prop.store(fos, "");
}
}
Properties示例
最新推荐文章于 2021-10-19 10:59:46 发布