我正在尝试创建一个从 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;
}
}