如何解决在8520模拟器中传输类java.io.IOException失败

时间:2012-04-11 11:28:15

标签: java

当我点击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;
}

0 个答案:

没有答案