如题,这个程序虽然运行正常,但异常的抛的都是Exception,感觉这样不太精确,能不能有高手指点一下,这些地方该怎么抛异常才最准确,,这一块一直没弄太懂。
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.URLConnection;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class WebKiller {
public static void main(String[] args)throws Exception {
Web("http://tieba.baidu.com/f?kw=lol");
//Txt();
}
public static void Web(String s)throws Exception
{
URL url=new URL(s);
URLConnection uc=url.openConnection();
BufferedReader buf=new BufferedReader(new InputStreamReader(uc.getInputStream()));
String line =null;
String ss="[g][a][m][e]\\w+";
Pattern p=Pattern.compile(ss);
while((line=buf.readLine())!=null){
Matcher m=p.matcher(line);
while(m.find()){
System.out.println(m.group());
}
}
buf.close();
}
public static void Txt()throws Exception{
BufferedReader buf=new BufferedReader(new FileReader("E:\\a.txt"));
String ss="\\w+@\\w+(\\.\\w+)+";
Pattern p=Pattern.compile(ss);
String len=null;
while((len=buf.readLine())!=null){
Matcher m=p.matcher(len);
while(m.find()){
System.out.println(m.group());
}
}
buf.close();
}
}
|
|