我希望将一个页面的内容转换为String。我尝试了一些方法来做到这一点。
我尝试使用的代码:
class GetWebContent extends AsyncTask<URL, String, String>{
@Override
protected String doInBackground(URL... url) {
URL mypage = new URL(url[0]); //HERE IS ERROR MalformedURLException
StringBuilder sb = new StringBuilder();
try {
BufferedReader in = new BufferedReader(
new InputStreamReader(
mypage.openStream()));
String inputLine;
while ((inputLine = in.readLine()) != null)
sb.append(inputLine);
in.close();
} catch (IOException e) {
Log.d("Exception",e.toString());
}
return sb.toString();
}
我编辑了代码,现在我收到了错误java.net.MalformedURLException
谢谢你的帮助。