【发布时间】:2013-04-09 03:52:57
【问题描述】:
您好,我刚刚完成了我的第一个 Java 小程序: http://st.fri.uniza.sk/~mudrak3/index2
它所做的基本上是遍历网站源代码并找到任何链接并将它们附加到 textArea 中。
如果我将该网站链接放入 textField (http://st.fri.uniza.sk/~mudrak3/index2) 并点击按钮,则一切正常。按钮事件:
private void button1ActionPerformed(java.awt.event.ActionEvent evt) {
textArea1.setText("\f");
try {
ArrayList<String> array = new ArrayList<String>();
ArrayList<String> vystup = new ArrayList<String>();
URL adresa;
adresa = new URL(textField1.getText());
BufferedReader kod = new BufferedReader(new InputStreamReader(adresa.openStream()));
String riadok;
while ((riadok = kod.readLine()) != null) {
array.add(riadok);
String[] pom = riadok.split(" ");
String xxx;
Pattern pattern = Pattern.compile("http://[^ \"]+");
for (int i = 0; i < pom.length; i++) {
xxx = pom[i];
Matcher matcher = pattern.matcher(xxx);
if (matcher.find()) {
textArea1.append(matcher.group(0) + "\n");
}
}
}
textArea1.append("---------Koniec---------");
} catch (MalformedURLException ex) {
JOptionPane.showMessageDialog(null, "Zle zadana URL !");
} catch (IOException ex) {
JOptionPane.showMessageDialog(null, "IOException !");
}
}
任何其他网站都不起作用。当我运行小程序时,此应用程序在 NetBeans 中运行,但在网站上不运行。有什么帮助吗?
【问题讨论】: