上代码 
- import java.io.*;
 
 - import java.util.*;
 
 - public class Monday
 
 - {
 
 -         public static void main(String[] args) throws Exception
 
 -         {
 
 -                 File file=new File("Property.txt");
 
 -                 if(!file.exists())
 
 -                         file.createNewFile();
 
 -                 FileInputStream fis=new FileInputStream(file);
 
  
-                 //①注意下面这句代码
 
 -                 FileOutputStream fos=new FileOutputStream(file);
 
 -                 Properties prop=new Properties();
 
 -                 prop.load(fis);
 
 -                 String value=prop.getProperty("times");
 
 -                 int count=0;
 
 -                 if(value!=null){
 
 -                         count=Integer.parseInt(value);
 
 -                         if(count>=5){
 
 -                                 System.out.println("Game Over!");
 
 -                                 return;
 
 -                         }
 
 -                 }
 
 -                 count++;
 
 -                 prop.setProperty("times",count+"");
 
 -                 
 
 -                 //②注意下面这句代码
 
 -                 //FileOutputStream fos=new FileOutputStream(file);
 
 -                 prop.store(fos,"");
 
 -                 fos.close();
 
 -                 fis.close();
 
 -         }
 
 - }
 
  复制代码 
 
同样一句代码,放在①的位置就起不到作用,放在②的位置就能,为啥?求教。 
 
PS:代码来源于毕老师视频,第20天-14。PS2:之前问过,囧的是刚发帖,网站系统就挂了…… 
 |   
        
 
    
    
    
     
 
 |