记录程序的重启次数

File file = new File("b.txt");
        int count = 0;
        FileInputStream fis = null;
        FileOutputStream fos = null;
        if(!file.exists())
        {
            try {
                file.createNewFile();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }

        try {
            fis = new FileInputStream(file);
            Properties pro = new Properties();
            pro.load(fis);
            String value = pro.getProperty("name");

            if(value!=null)
            {
                count = Integer.parseInt(value);
                if(count>=5)
                {
                    throw  new RuntimeException("使用次数已到");
                }
            }
            count++;
            pro.setProperty("name", String.valueOf(count));
            fos = new FileOutputStream(file);
            pro.store(fos, "");

        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            if(null != fos){
                try {
                    fos.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            if(null != fos){
                try {
                    fis.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
        log.info("!!!!!!!!!!!!!!!"+count);
原文地址:https://www.cnblogs.com/gaomanito/p/10904181.html