我正在嘗試做一個從URL獲取源代碼的類。我不明白爲什麼我收到了這條線「找不到符號錯誤」:爲什麼我得到一個「無法找到符號」錯誤
catch (MalformaedURLException e)
如果有人能解釋什麼是錯,這將是美好的...謝謝
這是我整個的代碼:
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.URLConnection;
import java.net.MalformedURLException;
public class SourceCode
{
private String source;
public SourceCode(String url)
{
try
{
URL page = new URL(url);
this.source = getSource(page);
}
catch (MalformedURLException e)
{
e.printStackTrace();
}
}
public String getSource(URL url) throws Exception
{
URLConnection spoof = url.openConnection();
BufferedReader in = new BufferedReader(new InputStreamReader(spoof.getInputStream()));
String strLine = "";
spoof.setRequestProperty("User-Agent", "Mozilla/4.0 (compatible; MSIE 5.5; Windows NT 5.0; H010818)");
while ((strLine = in.readLine()) != null)
{
strLine = strLine + "\n";
}
return strLine;
}
}
您需要導入'java.net.MalformedURLException' – Apurv 2013-03-05 05:57:43
拼寫爲MalformedURLException的是錯誤的.... – Pragnani 2013-03-05 06:05:59