2010-05-07 124 views

回答

2

高級視圖:您從HttpConnection打開OutputStream並將數據寫入該輸出流。主要的問題是要選擇使用哪個網絡連接(我建議您查看this, unless you're on OS 5.0 which has a similar feature built in)。至於通過FTP上傳會比較困難,因爲BlackBerry API不支持FTP,所以您必須查看。在使用SocketConnection和實施FTP自己的一部分

下面是一些代碼,讓你開始:

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); 
} 

當然,你需要處理異常,關閉流,檢查它是否已經上傳了成功等

+0

我可能是錯的,但這不會在HTTP表單上發揮作用。擁有HTTP標頭,如類型和長度以及邊界字符串。對? – Brenden 2011-01-20 23:06:18

+0

「InputStream in」中的數據長度是否存在限制? – CAMOBAP 2013-04-21 17:29:46