记录程序的重启次数
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);
既然我已经踏上这条道路,那么,任何东西都不应妨碍我沿着这条路走下去!!!!!!!!!! !!! ! !! !
个人公众号《后端技术开发之路》,欢迎您关注!
如果您觉得我写还不过,请打赏下在下吧!【高木子】!