更新时间:2022-06-27 05:54:59
我使用 commons-io CountingInputStream ,它可以帮到你。一个完整而简单的例子:
I'd use a commons-io CountingInputStream, which would do the job for you. A full but trivial example:
public long countContent(URL feedurl) {
CountingInputStream counter = null;
try {
HttpURLConnection con = (HttpURLConnection) feedurl.openConnection();
counter = new CountingInputStream(con.getInputStream());
String output = IOUtils.toString(counter);
return counter.getByteCount();
} catch (IOException ex) {
throw new RuntimeException(ex);
} finally {
IOUtils.closeQuietly(counter);
}
}