Java中获取网络资源的大小

URLConnection urlConnection = new URL("https://www.baidu.com").openConnection();
long contentLengthLong = urlConnection.getContentLengthLong();
System.out.println(contentLengthLong);
long contentLength = urlConnection.getHeaderFieldLong("Content-Length", -1);
System.out.println(contentLength);
String headerField = urlConnection.getHeaderField("Content-Length");
System.out.println(headerField);

 

你可能感兴趣的:(Java)