如何上传通过HTTP网站的文件? (黑莓) [英] how to upload the file through http to the website? (Blackberry)

查看:194
本文介绍了如何上传通过HTTP网站的文件? (黑莓)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要通过HTTP或FTP上传文件到黑莓JDE的网站。

I need to upload a file through http or ftp to the website in blackberry jde.

推荐答案

高级视图:您是从的 HttpConnection的和你的数据写入到该输出流。主要的问题将被选择使用哪个网络连接(我建议在看的这一点,除非你在OS 5.0具有内置了类似的功能)。至于通过FTP上传,这将是较为困难的,因为有内置的黑莓API的FTP不支持,而不是你要看看使用的 SocketConnection处和FTP自己。在实施部分

High level view: You open an OutputStream from an HttpConnection and write your data into that output stream. The main problem is going to be choosing which network connection to use (I recommend looking at this, unless you're on OS 5.0 which has a similar feature built in). As to uploading through FTP that will be somewhat more difficult as there is no support for FTP built into the BlackBerry API instead you'll have to look at using a SocketConnection and implementing part of FTP yourself.

下面是一些code,让你开始:

Here's some code to get you started:

HttpConnection httpConn = (HttpConnection) Connector.open("<URL>");
FileConnection fileConn = (FileConnection) Connector.open("file:///<path>");
InputStream in = fileConn.openInputStream();
OutputStream out = httpConn.openOutputStream();
byte[] buffer = new byte[100];
int bytesRead = 0;
while((in.read(buffer) = bytesRead) > 0)
{
   out.write(buffer, 0, bytesRead);
}

当然,你需要处理异常,关闭流,检查它是否已经成功上传等

Of course you'll need to deal with exceptions, close the streams, check that it was uploaded successfully, etc

这篇关于如何上传通过HTTP网站的文件? (黑莓)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆