服务热线:13616026886

技术文档 欢迎使用技术文档,我们为你提供从新手到专业开发者的所有资源,你也可以通过它日益精进

位置:首页 > 技术文档 > JAVA > 新手入门 > 基础入门 > 查看文档

从outlook导入email地址


  outlook有一种email地址格式,采用逗号分隔开字段,扩展名叫csv。
  例如:
  "姓名","称谓","单位名称","部门","职务","邮政地址","邮政编码","电话","传真","统一编码","其他电话","单位其他","移动电话","呼机","主页","电子邮件","备注"
  
  下面写个程序打开csv文件,每行读取只用第一个逗号前的字符串作为姓名,email地址匹配格式取第一个(位置无关)粗陋程序如下:
  
   private static final string repmail ="([//w.-]+[@]{1}((//w)+[.]){1,3}(//w)+)";
   private static final string repname =".+?,";
   pattern mailpattern = pattern.compile(repmail );
   pattern namepattern = pattern.compile(repname);
   file file = new file("test.csv");
   fileinputstream is = new fileinputstream(file);
   bufferedreader br = new bufferedreader(new inputstreamreader(is));
      string input = null;
   arraylist list = new arraylist();
    while((input = br.readline())!=null){
    matcher matchermail = mailpattern.matcher(input);
    matcher matchername = namepattern.matcher(input);
    string[] card = new string[2];
    if(matchername.find()){
     card[0] = matchername.group(0).replaceall("/"","");
    }
      if(matchermail.find()){
       card[1] = matchermail.group(0);
    }
    if(card[0]==null || card[0].equals("") || card[1]==null || card[1].equals("")){
     continue;
    }
    list.add(card);
   }//输出 for(int i=0;i       system.out.println(((string[])list.get(i))[0] + ":" + ((string[])list.get(i))[1]);
   }

扫描关注微信公众号