我从我的黑莓 java 代码中获取 net.rim.device.api.io.ConnectionClosedException。下面代码中突出显示的是引发异常的行。
hc = (HttpConnection) Connector.open(url);
hc.setRequestProperty("Content-Type", "multipart/form-data; boundary=" + getBoundaryString());
hc.setRequestMethod(HttpConnection.POST);
hc.setRequestProperty(HttpProtocolConstants.HEADER_ACCEPT_CHARSET,
"ISO-8859-1,utf-8;q=0.7,*;q=0.7");
hc.setRequestProperty(HttpProtocolConstants.HEADER_CONTENT_LENGTH ,Integer.toString(fileBytes.length));
OutputStream dout = hc.openOutputStream();
dout.write(boundaryMessage.getBytes());
dout.write(this.postBytes);
dout.write(endBoundary.getBytes());
dout.close();
int ch;
**is = hc.openInputStream();** //exception raised here
if(hc.getResponseCode()== HttpConnection.HTTP_OK)
{
while ((ch = is.read()) != -1)
{
bos.write(ch);
}
res = bos.toByteArray();
System.out.println("res loaded..");
}
else {
System.out.println("Unexpected response code: " + hc.getResponseCode());
hc.close();
return null;
}
}
catch(IOException e)
{
System.out.println("====IOException : "+e.getMessage()+" Class: "+e.getClass());
}
catch(Exception e1)
{
//e1.printStackTrace();
System.out.println("====Exception : "+e1.getMessage()+" Class: "+e1.getClass());
}
finally
{
try
{
if(bos != null)
bos.close();
if(is != null)
is.close();
if(hc != null)
hc.close();
}
catch(Exception e2)
{
e2.printStackTrace();
System.out.println("====Exception : "+e2.getMessage());
}
}
我应该怎么做才能纠正这个?有人可以帮忙吗?提前致谢。