这样的Exception该如何解决?
public static void main(String[] args) throws Exception {
String[] urls = {
"http://mil.news.sina.com.cn/2012-04-10/0428687123.html",
"http://mil.news.sina.com.cn/2012-04-12/0731687387.html",
"http://news.sina.com.cn/c/2012-04-13/044224264609.shtml"
};
final Pattern titlePattern = Pattern
.compile("<h1 id=\"artibodyTitle\".*?>(.*?)</h1>");
final Pattern wordCountPattern = Pattern.compile("\u515a|\u56fd\u5bb6");
for (final String url : urls) {
new Thread() {
public void run() {
BufferedReader reader = null;
try {
reader = new BufferedReader(new InputStreamReader(
new URL(url).openStream(), "GB2312"));
String line;
String title = null;
int[] count = new int[2];
while ((line = reader.readLine()) != null) {
if (title == null) {
Matcher titleMatcher = titlePattern.matcher(line);
if (titleMatcher.find()) {
title = titleMatcher.group(1);
}
}
Matcher wordCountMatcher = wordCountPattern.matcher(line);
while (wordCountMatcher.find()) {
String word = wordCountMatcher.group();
count[word.length() >> 1]++;
}
}
if (count[0] > count[1]) {
throw new RuntimeException(
String.format("%s[%s] \u515a:%d > \u56fd\u5bb6:%d",
title,
url,
count[0],
count[1]));
}
System.out.printf("%s[%s] is good!", title, url);
} catch (IOException ex) {
ex.printStackTrace();
} finally {
if (reader != null) {
try {
reader.close();
reader = null;
} catch (Exception ex) {
}
}
}
}
}.start();
}
}
...全文
相关推荐
Java throw Exception实现异常转换
主要介绍了Java throw Exception实现异常转换,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下
正确解决std::bad_exception异常的有效解决方法
正确解决std::bad_exception异常的有效解决方法
成功解决Array Index Out Of Bounds Exception问题
成功解决Array Index Out Of Bounds Exception问题 目录 解决问题 解决方法 解决问题 Array Index Out Of Bounds Exception 解决方法 数组索引越界异常:即数组下标号超出数组长度; ...
解决QuickCHM不能在Win7运行的问题,缺少系统补丁文件(DhtmlEd.msi ).rar
解决QuickCHM不能在Win7运行的问题,缺少系统补丁文件(DhtmlEd.msi ),现分享解决方案给大家! win7运行QuickCHM报错如下: Exception?EOleSysError?in?module?QuickCHM.exe?at?00081E9D?没有注册类别.
Windows Exception Handling
Windows Exception Handling


Java SE
