2
是在調用disconnect()後仍然可用的InputStream嗎?確實HttpUrlConnection.disconnect關閉了InputStream?
我想爲HTTP請求創建一個助手類,它將返回InputStream,但關閉連接。可能嗎 ?
例如:
public InputStream Get(String url) {
URL u = new URL(url);
HttpUrlConnection con = (HttpUrlConnection) url.openConnection();
InputStream in = null;
try {
in = con.getInputStream();
} finally {
con.disconnect();
}
return in;
}
'中= com.getInputStream();'???? com爲什麼?它看起來像你的代碼中有拼寫錯誤。 – Lucifer
@Lucifer typo我猜:HttpUrlConnection con –
@LazyNinja,從eclipse中看它的純副本粘貼的縮進,那它怎麼可能是錯字呢? – Lucifer