Properties、次数配置文件

import java.io.*;
import java.util.Properties;
public class PracticeUsed  {

    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,"haha");
        
        fos.close();
        fis.close();
        
    }
}

 

posted @ 2019-10-11 15:05  蚂蚁雅黑1010  阅读(114)  评论(0)    收藏  举报