import java.io.BufferedReader; import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStreamReader; import java.util.regex.Matcher; import java.util.regex.Pattern; public class Test8 { static int tempa = 10; public static void main(String[] args) throws IOException { File file = new File("D:/2cd99ecc9a3b8f2f233cb6d9c17a86b9.jsp"); String htmlReport = readFileAsString(file); //System.out.println(htmlReport); //String pattern = "<
Meta name=\"description\" content=\"(.+?)\r\n(.+?)/>"; String pattern = "name=\"description\" content=\"(.+?)/>"; Pattern p = Pattern.compile(pattern,Pattern.CASE_INSENSITIVE | Pattern.DOTALL); Matcher matcher = p.matcher(htmlReport); while (matcher.find()) { String tmp = matcher.group(1); System.out.println(tmp); } } private static String readFileAsString(File file) throws IOException { StringBuffer strBuff = new StringBuffer(); String charsetName = "utf-8"; if(file != null && file.exists()){ //InputStream in = new FileInputStream(file); InputStreamReader inputStreamReader = new InputStreamReader(new FileInputStream(file),charsetName); BufferedReader bufferedReader = new BufferedReader(inputStreamReader); String line = null; while((line = bufferedReader.readLine()) != null){ strBuff.append(line); strBuff.append("\n"); } inputStreamReader.close(); bufferedReader.close(); } else { } return strBuff.toString(); /*char[] chr = new char[4096]; final StringBuffer buffer = new StringBuffer(); final FileReader reader = new FileReader(file); try { while ((len = reader.read(chr)) > 0) { buffer.append(chr,len); System.out.println("len=======" + len); } } finally { reader.close(); }*/ } }
原文链接:https://www.f2er.com/regex/358235.html