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(); 
        } 
} 
 
 |