how to upload the file through http to the website? (Blackberry)

流过昼夜 提交于 2019-12-23 02:18:22

问题


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


回答1:


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.

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



来源:https://stackoverflow.com/questions/2788554/how-to-upload-the-file-through-http-to-the-website-blackberry

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!