Hello,
I use a regular expression to find all email addresses that are found in a text file. Here is my source code
But this is not working for me, I request that you just go through the code and see if you have missed something. And please guide me if I have mistaken somewhere.Code:String txt; ArrayList ls = <String> new ArrayList <String>(0); FileReader in; try { in = new FileReader("/ locations / file.txt"); } catch (FileNotFoundException e) { throw new Exception("Unable to open file"E); } / / Iterate over the file int c; try { while ((c = in.read()) != -1) { txt = txt + (char) c; } } catch (IOException e) { throw new Exception("Unable to read file"E); } / / Definition of regexp AChercher Pattern = Pattern.compiles("[_A-Za-z0-9-] + (\\. [_A-Za-z0-9-]+)*@" + "[A-Za-z0-9-] + (\\. [A-Za-z0-9-]+)*(\\. [_A-Za-z0-9-] +) "); mth = aChercher researcher.matcher(txt); / / Search the address while (researcher.find()) { String email = researcher.group(); ls.add(email); }
Bookmarks