Here you can find the source of readLinesWithPattern(File file, Pattern pattern)
public static ArrayList<String> readLinesWithPattern(File file, Pattern pattern)
//package com.java2s; //License from project: Open Source License import java.io.File; import java.io.FileNotFoundException; import java.util.ArrayList; import java.util.Scanner; import java.util.regex.Pattern; public class Main { public static ArrayList<String> readLinesWithPattern(File file, Pattern pattern) { ArrayList<String> strs = new ArrayList<>(); try {/*from w ww . jav a 2 s .c o m*/ Scanner sc = new Scanner(file); while (sc.hasNextLine()) { Scanner lineSc = new Scanner(sc.nextLine()); String str = lineSc.findInLine(pattern); if (str != null) { strs.add(str.trim()); } } } catch (FileNotFoundException ex) { // Ignore } return strs; } }