本程序的功能是,根据用户输入的文件名,在相应的文件内容中查找匹配给定模式的字符串,并将这些字符串显示出来。模式串为“href="…"”。请填写横线处的内容。注意:请勿改动main()主方法和其他已有语句内容,仅在横线处填入适当语句。import java.io.*;import java.util.regex.*;import javax.swing.*;public class Example2_10{public static void main(String [] argv){final String patternString ="href\\s*=\\s*(\"[^\"]*\"|[^\\s>])\\s*;String fileName ;try{System. out. print ( "请输入html 文件的文件名: ");InputStreamReader in = new InputStreamReader(System.in);BufferedReader imput = new BufferedReader(in);fileName = imput.readLine();if(fileName.equals(" "))return;StringBuffer buffer = new StringBuffer();File file = new File(fileName);FileInputStream readfile = new FileInputStream(file);for(int c = 0; (c = readfile.read()) != -1; )buffer.append((char)c);Pattern pattern = Pattern.compile(_____________ Pattern.CASE_INSENSITIVE);Matcher matcher =________;while (marcher. find ()){int start = matcher.start();int end = matcher.end();String match = buffer.substring(start, end);System.out.println (match);}}catch (Exception excption){System. out.println (excption. getMessage ());}System.exit(O);}}
本程序的功能是,根据用户输入的文件名,在相应的文件内容中查找匹配给定模式的字符串,并将这些字符串显示出来。模式串为“href="…"”。请填写横线处的内容。
注意:请勿改动main()主方法和其他已有语句内容,仅在横线处填入适当语句。
import java.io.*;
import java.util.regex.*;
import javax.swing.*;
public class Example2_10
{
public static void main(String [] argv)
{
final String patternString =
"href\\s*=\\s*(\"[^\"]*\"|[^\\s>])\\s*;
String fileName ;
try
{
System. out. print ( "请输入html 文件的文件名: ");
InputStreamReader in = new InputStreamReader(System.in);
BufferedReader imput = new BufferedReader(in);
fileName = imput.readLine();
if(fileName.equals(" "))
return;
StringBuffer buffer = new StringBuffer();
File file = new File(fileName);
FileInputStream readfile = new FileInputStream(file);
for(int c = 0; (c = readfile.read()) != -1; )
buffer.append((char)c);
Pattern pattern = Pattern.compile(
_____________ Pattern.CASE_INSENSITIVE);
Matcher matcher =________;
while (marcher. find ())
{
int start = matcher.start();
int end = matcher.end();
String match = buffer.substring(start, end);
System.out.println (match);
}
}
catch (Exception excption)
{
System. out.println (excption. getMessage ());
}
System.exit(O);
}
}