日期:2014-05-20 浏览次数:20864 次
import java.io.*; import java.util.*; import java.util.regex.Matcher; import java.util.regex.Pattern; public class TestEmail { public static int i = 0; public static void main(String[] args) throws IOException{ FileReader fr = new FileReader("c://hello.txt"); BufferedReader br = new BufferedReader(fr); String line = ""; while((line = br.readLine()) != null){ email(line); } fr.close(); br.close(); System.out.print("i == " + i); } public static void email(String s) throws IOException{ FileWriter fw = new FileWriter("c://hello2.txt"); // BufferedWriter bw = new BufferedWriter(fw); String str = ""; Pattern p = Pattern.compile("\\w*+\\@\\w*\\.[\\w]*"); Matcher m = p.matcher(s); if(m.find()){ ++i; str = m.group(); System.out.println(str); fw.write(str); } } }