从outlook导入email地址

王朝other·作者佚名  2008-05-19
宽屏版  字体: |||超大  

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]);

}

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
© 2005- 王朝网络 版权所有