1

我想使用 BlackBerry 应用程序通过 Internet 从服务器下载文件。使用哪种协议并不重要:FTP、HTTP 或其他协议都可以。我只需要用户单击“下载”按钮,然后应用程序从服务器下载此文件。

我不知道怎么做。我尝试了一些解决方案。其中一个我需要一个 HttpConnectorFactory ,但这不在我的 API 中。

几天来我一直在寻找我的问题的答案,但我还没有找到有效的解决方案。

我尝试过的解决方案的链接:

4

1 回答 1

2

试试这个 -

ConnectionFactory connFact = new ConnectionFactory();
ConnectionDescriptor connDesc = connFact.getConnection(your_url);
HttpConnection httpConn = (HttpConnection) connDesc.getConnection();
try {
    httpConn.setRequestMethod(HttpConnection.GET);
    InputConnection inputConn = (InputConnection) httpConn;
    InputStream is = inputConn.openInputStream();
    byte[] data =IOUtilities.streamToBytes(is);
    //the value in data will be the bytes of your file.
    // now if you want to save the file, you can do it here......
} catch (IOException e) {
    e.printStackTrace();
}
于 2012-11-30T09:10:28.127 回答