2010-02-26 90 views
2

我想使用jakarta的公共HttpClient庫。寫入HttpEntity到文件

我想我在這裏很愚蠢,但我無法弄清楚如何編寫一個完整的HttpEntity文件。

我想:

FileOutputStream os = new FileOutputStream(f); 

e.writeTo(os); 
while (e.isStreaming()) { 
    e.writeTo(os); 
} 

其中E是我的HttpEntity,f是我的文件。我只能得到任何文件的第一個8KB,我想是因爲在某處緩衝。任何想法我怎麼得到其餘的?

回答

1

解決了它。

我需要強制響應對象使用BufferedHttpEntity:

HttpEntity entity = rsp.getEntity(); 
BufferedHttpEntity buf = new BufferedHttpEntity(entity); 
1
response = httpclient.execute(get); 
is = response.getEntity().getContent(); 
IOUtils.copy(is,fileWriter);