我正在从源中提取地址,但某些提取物在地址前面没有 http://,我如何检查地址是否有 http://,如果他们没有,我如何添加 http:// 前面?:O
得到这个错误,我猜是由于 http://infront 的“缺乏”
java.net.MalformedURLException: no protocol: www.speedtest.net
at java.net.URL.<init>(URL.java:583)
at java.net.URL.<init>(URL.java:480)
at java.net.URL.<init>(URL.java:429)
at a.PageRead.r(PageRead.java:29)
at a.ThreadDownloaderWriter.run(ThreadDownloaderWriter.java:35)
at java.lang.Thread.run(Thread.java:722)
public StringBuilder readPage() {
try {
URL url = new URL(this.strURL);
System.out.println(this.strURL);
BufferedReader reader = new BufferedReader(new InputStreamReader(url.openStream()));
String line;
StringBuilder sb = new StringBuilder();
while ((line = reader.readLine()) != null) {
sb.append(line + "\n");
}
reader.close();
return sb;
} catch (MalformedURLException e) {
e.printStackTrace();
return new StringBuilder("");
} catch (IOException e) {
e.printStackTrace();
return new StringBuilder("");
}
}