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

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

© 825176857 中级黑马   /  2015-7-13 22:43  /  368 人查看  /  2 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文

public class CountDemo {
     
    public static void main(String[] args) {
         
        if(! checkLogin()){
            System.out.println("Sorry, you cann't login .");
            System.exit(0);
        }
        System.out.println("Welcome ..");
         
         
    }

    private static boolean checkLogin() {
        // TODO Auto-generated method stub
         
        FileReader fr = null;
        File file = null;
        FileWriter fw = null;
        BufferedWriter bw = null;
         
        try {
            
            file = new File("setup.ini");
            if(!file.exists()){
                file.createNewFile();
            }
            fr = new FileReader("setup.ini");
            
            Properties pro = new Properties();
            pro.load(fr);
            
            int key = 0;
            if(pro.getProperty("count") != null){
                String p = pro.getProperty("count");
                 
                key = Integer.parseInt(p) + 1;
                 
                if(key > 5){
                    return false;
                }
                 
            }else{
                key = 1;
            }
            
            pro.setProperty("count", String.valueOf(key));
            
            fw = new FileWriter("setup.ini");
            bw = new BufferedWriter(fw);
            String comments = "You logined : ";
            pro.store(bw, comments);
            
            
        } catch (FileNotFoundException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            
            if(fr != null){
                try {
                    fr.close();
                } catch (IOException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            }
            
            if(bw != null){
                try {
                    bw.close();
                } catch (IOException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            }
            
            if(fw != null){
                try {
                    fw.close();
                } catch (IOException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            }
        }
         
        return true;
         
    }
     
}

2 个回复

倒序浏览
学习了,感谢楼主
回复 使用道具 举报
大哥,你这没注释啊,希望还是加一下吧,至少把每个方法功能简答介绍一下下么。
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 加入黑马