龙须面

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理
 1 import java.io.FileInputStream;
 2 import java.io.FileOutputStream;
 3 import java.util.Properties;
 4 
 5 public class Property {
 6     public static void main(String[] args) {
 7         Properties p = new Properties();
 8         int counter = 1;
 9         try {
10             p.load(new FileInputStream("counter.txt"));
11         } catch (Exception e) {
12             p.setProperty("counter", String.valueOf(counter));
13         }
14         counter = Integer.parseInt(p.getProperty("counter"));
15         System.out.println("第" + counter + "次运行");
16 
17         counter++;
18         p.setProperty("counter", String.valueOf(counter));
19         try {
20             p.store(new FileOutputStream("counter.txt"),
21                     "This software is runned counter:");// 第二个参数是对这个文件的注释,不支持中文的
22         } catch (Exception e) {
23             e.printStackTrace();
24         }
25 
26     }
27 }
posted on 2012-06-29 18:24  木子小黑  阅读(199)  评论(0编辑  收藏  举报