写了几遍,跟着老毕的逻辑也转了几圈,我写的还是整不出来??,求指点- public static void run_count()
- {
- Properties p = new Properties();
- File file = new File("d:\\test\\count3.ini");
- if(!file.exists())
- {
- try {
- file.createNewFile();
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- FileInputStream fis = null;
- FileOutputStream fos = null;
- try {
- fis = new FileInputStream(file);
- fos = new FileOutputStream(file);
- p.load(fis);
- int count = 0;
- String value = p.getProperty("time");
- if(value != null)
- {
- count = Integer.parseInt(value);
- if(count >= 5)
- {
- System.out.println("到期了");
- return;
- }
- }
- count++;
- p.setProperty("time", count+"");
- p.store(fos, "");
- } catch (FileNotFoundException e) {
- e.printStackTrace();
- } catch (IOException e) {
- e.printStackTrace();
- }finally{
- try {
- if(fos != null)
- fos.close();
- } catch (IOException e) {
- e.printStackTrace();
- }
- try {
- if(fis != null)
- fis.close();
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- }
复制代码
|
|