当我点击url而不是给出错误时(无法传输::: class java.io.IOException) 如何解决这个错误。
public InputStream fetchAndPopulateData(String url) {
HttpConnection hc = null;
InputStream is = null;
try {
hc = (HttpConnection) Connector.open(url
+ new InternetType().internetType());
hc.setRequestMethod(HttpConnection.GET);
int rc = hc.getResponseCode();
if (rc == HttpConnection.HTTP_OK) {
is = hc.openInputStream();
}
int ch;
StringBuffer sb = new StringBuffer();
InputStreamReader reader = new InputStreamReader(is);
while((ch = reader.read())!=-1){
sb.append((char)ch);
}
System.out.println("StringBuffer::::::::" + sb.toString());
} catch (IOException e) {
System.out.println(e.getMessage() + ":::" + e.getClass());
}
return is;
}