A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

public class PropertiesTest {
    public static void main(String[] args) throws IOException {
                BufferedReader bufr = null;
                BufferedWriter bufw = null;
                bufr = new BufferedReader(new FileReader("D:\\workspace\\exam\\src\\com\\itheima\\Review\\Prop.txt"));
                Properties prop = new Properties();

                prop.load(bufr); //放到这句前面count++不起效,后面就可以起效,不明白
                int count=0;
                String value = prop.getProperty("time");
                if(value!=null){
                        count = Integer.parseInt(value);
                        if(count==5){
                                System.out.println("您好,使用次数已到,拿钱!");
                                return ;
                        }
                }
                count++;
                //这句放到头部会让count++不起效,为什么?
                bufw = new BufferedWriter(new FileWriter("D:\\workspace\\exam\\src\\com\\itheima\\Review\\Prop.txt"));
                prop.setProperty("time", count+"");
                prop.store(bufw,"");

                Set set = prop.keySet();
                Iterator it = set.iterator();
                while(it.hasNext()){               
                        Object key = it.next();
                        Object value1 = prop.get(key);
                        System.out.println(key+"::"+value1);
                }

                bufr.close();
                bufw.close();
        }
}

评分

参与人数 1黑马币 +5 收起 理由
何伟超 + 5

查看全部评分

2 个回复

正序浏览
  1.          if(value!=null){
  2.                         count = Integer.parseInt(value);
  3.                         if(count==5){
  4.                                 System.out.println("您好,使用次数已到,拿钱!");
  5.                                 return ;
  6.                         }
  7.                 }
  8.                 count++;
复制代码

这句话的意思是得到的次数大于等于5就告诉他使用次数已经到了
如果没有大于5则count++    你现在把count放在前面 等于 每次从prop.txt
种读取数据  然后原样写入 当然就没效果了

评分

参与人数 1技术分 +1 收起 理由
zzkang0206 + 1

查看全部评分

回复 使用道具 举报
你放到这句int count=0;前面怎么会有效啊

评分

参与人数 1黑马币 +5 收起 理由
何伟超 + 5

查看全部评分

回复 使用道具 举报
您需要登录后才可以回帖 登录 | 加入黑马