普遍存在的grep命令的简单实现。
import java.io.BufferedReader; import java.io.FileReader;/** N o w J a v a . c o m - 时代Java 提 供 **/ import java.util.regex.Matcher; import java.util.regex.Pattern; public class Main { public static void main(String[] argv) throws Exception { Pattern pattern = Pattern.compile("test"); Matcher matcher = pattern.matcher("test"); String file = "text.txt"; BufferedReader br = new BufferedReader(new FileReader(file)); String line; while ((line = br.readLine()) != null) { matcher.reset(line);