我想通过互联网使用BlackBerry应用程序从服务器下载文件。 使用哪种协议并不重要:FTP,HTTP或其他东西都可以。我只需要用户点击“下载”按钮,然后应用程序就会从服务器下载此文件。
我不知道怎么做。我尝试了一些解决方案。在一个我需要一个HttpConnectorFactory但这不在我的API。
我已经搜索了几天的问题答案,但我找不到有效的解决方案。
我尝试过的解决方案的链接:
答案 0 :(得分: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();
}