黑马程序员技术交流社区

标题: 猜数字小游戏plus [打印本页]

作者: 戈戈哥哥    时间: 2019-10-16 14:06
标题: 猜数字小游戏plus
public class PropertiesTest {    public static void main(String[] args) throws IOException {        //从文件中读取数据到Properties集合,用load()方法实现        Properties prop = new Properties();

       FileReader fr = new FileReader("myOtherStream\\game.txt");        prop.load(fr);        fr.close();

       //通过Properties集合获取到玩游戏的次数        String count = prop.getProperty("count");        int number = Integer.parseInt(count);

       //判断次数是否到到3次了        if(number >= 3) {            //如果到了,给出提示:游戏试玩已结束,想玩请充值(www.itcast.cn)            System.out.println("游戏试玩已结束,想玩请充值(www.itcast.cn)");        } else {            //玩游戏            GuessNumber.start();

           //次数+1,重新写回文件,用Properties的store()方法实现            number++;            prop.setProperty("count",String.valueOf(number));            FileWriter fw = new FileWriter("myOtherStream\\game.txt");            prop.store(fw,null);            fw.close();        }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
 
   } }





欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/) 黑马程序员IT技术论坛 X3.2