properties配置文件(练习)



import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Properties;

class Demo{
    public static void main(String[] args) throws IOException {
        Properties properties = new Properties();
        File file = new File("F:\\a.properties");
        if(!file.exists()) {
            file.createNewFile();
        }
        properties.load(new FileInputStream(file));
        
        int count = 0;
        
        String value = properties.getProperty("count");
        if(value!=null)
        count = Integer.parseInt(value);
        
        if(count == 3) {
            System.out.println("已经使用了三次, 请购买正版");
            System.exit(0);
        }count++;
            System.out.println("您已经使用了"+count+"次");
        properties.setProperty("count", count+"");
        properties.store(new FileOutputStream("F:\\a.properties"), "haha");
    }
}

你可能感兴趣的:(properties配置文件(练习))