我有一個(gè)InputStream,我將其傳遞給方法來(lái)進(jìn)行一些處理。我將在其他方法中使用相同的InputStream,但是在第一次處理之后,InputStream似乎在該方法內(nèi)部被關(guān)閉。我如何克隆InputStream發(fā)送到關(guān)閉他的方法?還有另一種解決方案?編輯:關(guān)閉InputStream的方法是來(lái)自lib的外部方法。我無(wú)法控制是否關(guān)閉。private String getContent(HttpURLConnection con) { InputStream content = null; String charset = ""; try { content = con.getInputStream(); CloseShieldInputStream csContent = new CloseShieldInputStream(content); charset = getCharset(csContent); return IOUtils.toString(content,charset); } catch (Exception e) { System.out.println("Error downloading page: " + e); return null; }}private String getCharset(InputStream content) { try { Source parser = new Source(content); return parser.getEncoding(); } catch (Exception e) { System.out.println("Error determining charset: " + e); return "UTF-8"; }}
添加回答
舉報(bào)
0/150
提交
取消