我想从诺基亚手机上传一个大文件到服务器,我使用下面的代码。此代码适用于小文件。当我想上传更大的文件(大约10mb)时,我收到内存不足的消息。有谁知道我怎样才能转换这个代码上传文件使用 多个httpConnections,每个连接发送一个文件块。我们假设服务器支持这一点。在J2ME中使用多个hppt连接上传大文件
fc = (FileConnection)Connector.open("file:///myfile", Connector.READ);
is = fc.openInputStream();
// opening http connection and outputstream
HttpConnection http = (HttpConnection)Connector.open(url, Connector.WRITE);
http.setRequestMethod(HttpConnection.POST);
http.setRequestProperty("Content-Type", type);
http.setRequestProperty("Connection", "close");
OutputStream os = http.openOutputStream();
int total = 0;
while (total < fileSize) {
byte b[] = new byte[1024];
int length = is.read(b, 0, 1024);
os.write(b, 0, length);
total += length;
}
os.flush();
int rc = http.getResponseCode();
os.close();
http.close();
os.flush不while循环里面工作。我会尝试使用分析器。我正在寻找像这样的解决方案:http://discussion.forum.nokia.com/forum/showthread.php?t=176546&highlight=upload+chunk(请参阅最新评论) – user75569 2009-12-11 08:06:01