| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | <br><br>importjava.io.File;importjava.io.FileReader;importjava.io.FileWriter;importjava.io.IOException;importjava.util.Properties;publicclassPropertiesTest {    publicstaticvoidmain(String[] args) throwsIOException {        File file = newFile("my.ini");        //犯傻的时候,我把这句写到这,还说每次读到的文件都是空的,傻了        //这样的话,每次程序一运行,就会覆盖以前有内容的配置文件        //FileWriter fileW = new FileWriter(file);        if(!file.exists()){            file.createNewFile();        }        System.out.println(file.exists());        Properties ps = newProperties();        ps.load(newFileReader(file));        intcount = 0;        ps.list(System.out);        String countStr = ps.getProperty("count");        if(countStr != null){            count = Integer.valueOf(ps.getProperty("count"));            if(count > 3){                thrownewRuntimeException("您已经登录3次,请付钱!");            }        }        count ++;        ps.setProperty("count", String.valueOf(count));        ps.store(newFileWriter(file), "properties");    }} | 
思路:
给启动程序添加配置文件,用于记录程序启动次数,每次启动,修改启动次数,当达到指定次数时抛出异常
记录程序启动次数,达到固定次数后不能使用,布布扣,bubuko.com
原文:http://www.cnblogs.com/lxricecream/p/3601217.html