一个实用小工具(允许程序运行的次数)

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Properties;


public class PropertiesDemo {


public static void main(String[] args) throws IOException {
//一个实用小工具(允许程序运行的次数)
File file = new File("E:\\info.properties");
if (!file.exists()) {
file.createNewFile();
}
FileInputStream fis = new FileInputStream(file);
Properties proper = new Properties();
proper.load(fis);
String value = proper.getProperty("time");
int count = 0;
if (value != null) {
count = Integer.parseInt(value);
if (count >= 5) {
throw new RuntimeException("你的使用次数已经使用完毕,为保证程序正常使用请及时购买注册");
}
}
count++;
System.out.println("你能正常使用本软件的次数还有:"+(5-count)+"次。");
proper.setProperty("time", count+"");
FileOutputStream fos = new FileOutputStream(file);
proper.store(fos, "info");
        fos.close();
        fis.close();
}


}

你可能感兴趣的:(一个实用小工具(允许程序运行的次数))