Properties实例

23      /********************设计一个程序,当运行一次程序,配置文件自增1*****************
***/
24      //      思路:因为程序要一一对应关系取值,所以用到Map集合,又因要从文件中读取,所以应用Properties集合
25      //   程序中要读写文件,所以要用到FileInputStream和FileWriter
26      public static void propertyAdd()throws IOException
27      {
28              Properties prop=new Properties();
29              File f=new File("info.ini");
30              if(!(f.exists()))
31                      f.createNewFile();
32              FileInputStream fis=new FileInputStream(f);
33              prop.load(fis);
34              int count=0;
35              String value=prop.getProperty("name");
36              if(value!=null)
37                      count=Integer.parseInt(value);
38              FileWriter fw=new FileWriter(f);
39              prop.setProperty("name",++count+"");      //修改键值
40              //count++;
41              prop.store(fw,"");
42              if(count>=5)
43              {
44                      System.out.println("运行次数太多了");
45                      return;
46              }
47      }
48}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值