通过app打开Web / URL

时间:2012-10-01 03:19:31

标签: java-me midlet

我正在开发J2ME 您能不能帮我找出这段代码的错误:

HttpConnection c = null;

    try {
        c = (HttpConnection)Connector.open("http://www.mysite.com",Connector.READ_WRITE, true);
        c.setRequestMethod(HttpConnection.GET); //default
        is = c.openInputStream(); // transition to connected!
            int ch = 0;
        for(int ccnt=0; ccnt < 150; ccnt++) { // get the title.
            ch = is.read();
            if (ch == -1){
                break;
            }
                sb.append((char)ch);
        }
    }   
    catch (IOException x){
        x.printStackTrace();
    }
    finally{
        try     {
            is.close();
            c.close();
        } catch (IOException x){
            x.printStackTrace();
        }
    }
        System.out.println(sb.toString());


我正在尝试通过我的应用程序打开网站,谢谢之前:)

1 个答案:

答案 0 :(得分:3)

要在J2ME中打开URL,请在非系统线程中执行以下操作:

MIDlet.platformRequest("http://www.mysite.com/");