outlook有一种email地址名目,采用逗号离散隔字段,扩展名叫CSV。$ U( N: E8 i, S q4 V
例如:
# c- [, Q; L9 d& G. s4 S "姓名","称谓","单元名称","部门","职务","邮政地址","邮政编码","电话","传真","统一编码","其他电话","单元其他","移动电话","呼机","主页","电子邮件","备注"下面写个轨范打开csv文件,每行篡夺只用第一个逗号前的字符串作为姓名,email地址匹配名目取第一个(位置无关)粗陋轨范如下: private static final String repmail ="([\w.-]+[@]{1}((\w)+[.]){1,3}(\w)+)";, K7 }9 V2 i+ C% j- b
private static final String repname =".+?,";6 Y e0 w; E7 m) [
Pattern mailPattern = Pattern.compile(repmail );) u, E7 V: J" C' ?) X, _& l" q1 e
Pattern namePattern = Pattern.compile(repname);. c' k1 i! ^7 C" {( Z$ c' C; _( C
File file = new File("test.CSV");: B' {) r- R( W. B+ A2 P( ~& z
FileInputStream is = new FileInputStream(file);; W5 g/ ?& t1 C6 ]3 o* e
BufferedReader br = new BufferedReader(new InputStreamReader(is));( G" c4 D: z3 H% F/ H G9 @
String input = null;
! f' T( W7 `$ O o; g ArrayList list = new ArrayList();8 g7 [6 j; m ?0 q5 s4 W! Z
while((input = br.readLine())!=null){4 b) y4 K% d! A( ~
Matcher matchermail = mailPattern.matcher(input);( n/ }0 [9 J7 I+ G* k" W$ e: ]. c
Matcher matchername = namePattern.matcher(input);/ y7 }! B5 a& X; A; v
String[] card = new String;
h. G. P5 ~4 O7 d+ ] if(matchername.find()){; }( P4 q) k6 z/ d9 n
card[0] = matchername.group(0).replaceAll(""","");
4 }, m" z. y" ?" u }
; i3 y9 `: C, W if(matchermail.find()){9 l: y. l: a& ~$ o
card = matchermail.group(0);
) I( w; e1 j; _ }4 u8 B8 C& ^" Y" }7 n5 m
if(card[0]==null |