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

© zhoubinjian 金牌黑马   /  2016-4-26 13:07  /  444 人查看  /  0 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文

/*
        需求:程序运行的次数
        1.将count.ini的键值存到集合中
    用Properties集合当中的load()方法。
        2.读取键值,用计数器count计数
        3.把键值存入到集合中
        4.再用store()更新键值,存入到文件中。
*/
/*
import java.io.*;
import java.util.*;
class Demo
{
        public static void main(String[] args)throws IOException
        {
               
                removeDir();
        }
        public static void removeDir()throws IOException
        {
                File file=new File("count.ini");
                        if(!file.exists())
                                file.createNewFile();
                FileInputStream fis= new FileInputStream(file);
                Properties prop= new Properties();
                int count=0;
                prop.load(fis);
                String value=prop.getProperty("time");
                        if(value!=null)
                        {
                                count=Integer.parseInt(value);
                                if(count>=5)
                                {
                                        System.out.println("你使用的次数已到,交钱!");
                                return;
                                }
                        }
                        count++;
                        prop.setProperty("time",count+"");
                FileOutputStream out=new FileOutputStream(file);
                prop.store(out,"");
                //System.out.println(prop);
                fis.close();
                out.close();
        }
}
*/

0 个回复

您需要登录后才可以回帖 登录 | 加入黑马