网易邮件采集器(4)

邮件查看:用switch语句,根据不同的case,执行相应的查看方式

if (args.length > 0) {
            String s = args[0];

            switch (s) {
            case "account":

                try {
                    File f = new File(Constants.strFilePath, Constants.strFileName);

                    if (f.exists()) {
                        FileReader fr = new FileReader(f);

                        char[] ch = new char[1024];

                        int i = 0;

                        String str = "";
                        while ((i = fr.read(ch)) > 0) {
                            str += new String(ch, 0, i);
                        }

                        JSONObject jo = new JSONObject(str);
                        fr.close();
                        String userName = (String) jo.getJSONObject("account").get("username");
                        String password = (String) jo.getJSONObject("account").get("password");
                        System.out.println("account的username = " + userName);
                        System.out.println("account的password = " + password);
                    } else {
                        System.out.println("文件不存在");
                    }

                } catch (Exception e) {
                    e.printStackTrace();
                }

                break;

            case "status":
                int count = 0;
                int post = 0;

                File mf = new File("d:/mail/date");

                File[] ms = mf.listFiles();
                for (File y : ms) {
                    if (y.isFile())
                        count++;
                    else if (y.isDirectory()) {
                        // 判断是否包含附件
                        if (y.getName().contains("_attachment")) {
                            post++;
                        }
                    }

                }
                System.out.println("邮件数量:" + count + "封; 包含附件的邮件:" + post + "封");

                break;
            case "search":
                if (args.length > 1) {
                    int mail = 0;
                    String keyword = args[1];
                    if (new File("d:/mail/date").exists()) {
                        try {
                            File[] ms_ = new File("d:/mail/date").listFiles();
                            for (File y : ms_) {
                                if (y.exists()) {
                                    FileReader fr = new FileReader(y);
                                    JSONReader jr = new JSONReader(fr);
                                    MailGet mg = jr.readObject(MailGet.class);

                                    if (mg.getSubject().contains(keyword)) {
                                        mail++;
                                        System.out.println("符合搜索条件的第" + mail 
                                                + "封邮件:  标题:" 
                                                + mg.getSubject() + ",  文件名:"
                                                + y.getName());
                                    }

                                    fr.close();
                                    jr.close();
                                } else {
                                    System.out.println("文件不存在");
                                }

                            }

                        } catch (Exception e) {
                            e.printStackTrace();
                        }

                    }
                }
            }
        } else {

            System.out.println("请输入\"account\",\"status\"或\"search <keyword>\"");
        }
    }

 

转载于:https://www.cnblogs.com/wenwen123/p/5797109.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值