以下实例演示了如何获取远程文件的大小:
import java.net.URL; import java.net.URLConnection; public class Main { public static void main(String[] args) throws Exception { int size; URL url = new URL("http://www.runoops.com/wp-content/themes/runoops/assets/img/newlogo.png"); URLConnection conn = url.openConnection(); size = conn.getContentLength(); if (size
以上代码运行输出结果为:
文件大小为:4261 bytes