这样的Exception该如何解决?

shine333 2012-04-13 11:40:36
  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();
}
}
...全文
355 21 打赏 收藏 转发到动态 举报
写回复
用AI写文章
21 条回复
切换为时间正序
请发表友善的回复…
发表回复
潍一 2012-05-13
  • 打赏
  • 举报
回复
楼主的头像很不和谐啊。 -,-!
结贴是美德 2012-04-16
  • 打赏
  • 举报
回复
统计这些东西有意义么,一篇文章中有1w个\u515a,但是结尾有于句话,说所有这些都是为了\u56fd\u5bb6。
a395885670 2012-04-16
  • 打赏
  • 举报
回复
好河蟹的一个帖子
shine333 2012-04-16
  • 打赏
  • 举报
回复
up,下午结贴
shine333 2012-04-13
  • 打赏
  • 举报
回复
3个线程一律count[0]远远大于count[1]
shine333 2012-04-13
  • 打赏
  • 举报
回复
[Quote=引用 14 楼 的回复:]

\u515a=党
\u56fd=人
\u5bb6=民
[/Quote]
Concern 2012-04-13
  • 打赏
  • 举报
回复
出现敏感字眼会被河蟹的。[Quote=引用 14 楼 的回复:]
\u515a=党
\u56fd=人
\u5bb6=民
[/Quote]
小菜鸟的博客 2012-04-13
  • 打赏
  • 举报
回复
貌似是个牛逼帖子!!!!!!!!!!!!!!
  • 打赏
  • 举报
回复
\u515a=党
\u56fd=人
\u5bb6=民
yingle2000 2012-04-13
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 的回复:]
貌似有句说明了这点没有\u515a就没有新中国.............
所以\u515a 铁定大于 \u56fd\u5bb6
[/Quote]
看看u515a铸就的新中国的冰山一角:
\u559D\u6C34\u6B7B
\u8EB2\u732B\u732B
\u674E\u521A
\u6BD2\u5976\u7C89
\u6740\u7AE5
\u9ED1\u76D1\u72F1
yingle2000 2012-04-13
  • 打赏
  • 举报
回复
\u515a倒下,问题就解决了
Concern 2012-04-13
  • 打赏
  • 举报
回复
河蟹,真河蟹。
BearKin 2012-04-13
  • 打赏
  • 举报
回复
.......为了某些事情你还真是不遗余力啊
shine333 2012-04-13
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 的回复:]

楼主你是哪个单位的?!

你是为\u515a说话的,还是为\u56fd\u5bb6说话的?!
[/Quote]
2F说了,为\u4EBA\u6C11说话
丙寅 2012-04-13
  • 打赏
  • 举报
回复
这个不太会 钻研下了
游一游走一走 2012-04-13
  • 打赏
  • 举报
回复
貌似有句说明了这点没有\u515a就没有新中国.............
所以\u515a 铁定大于 \u56fd\u5bb6
MiceRice 2012-04-13
  • 打赏
  • 举报
回复
楼主你是哪个单位的?!

你是为\u515a说话的,还是为\u56fd\u5bb6说话的?!
cseu 2012-04-13
  • 打赏
  • 举报
回复
solution:add following line before Matcher wordCountMatcher = wordCountPattern.matcher(line);
line=line.replaceAll("\u515a","\u4EBA\u6C11");

62,614

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧