我试图编写一个程序,以分块格式从 Web 服务器获取文件。我正在尝试在 HTTP 3.0 API 中使用 ChunkedInputStream 类。当我运行代码时,它给了我“卡盘输入流意外结束”错误。我究竟做错了什么?这是我的代码:
HttpClient client = new DefaultHttpClient();
HttpGet getRequest = new HttpGet(location);
HttpResponse response = client.execute(getRequest);
InputStream in = response.getEntity().getContent();
ChunkedInputStream cis = new ChunkedInputStream(in);
FileOutputStream fos = new FileOutputStream(new ile("session_"+sessionID));
while(cis.read() != -1 )
{
fos.write(cis.read());
}
in.close();
cis.close();
fos.close();