提示:您可在线编辑运行本教程的实例 - 运行实例,去试试!
通过URL获取远程文件大小
//package com.nowjava; //n o w j a v a . c o m 提 供 import java.net.HttpURLConnection; import java.net.URL; public class Main { public static void main(String[] argv) throws Exception { String url = "nowjava.com"; System.out.println(getRemoteFileSize(url)); } public static long getRemoteFileSize(String url) { long size = 0; try { HttpURLConnection conn = (HttpURLConnection) (new URL(url)) .openConnection(); /** from * n o w j a v a . c o m - 时 代 Java **/ size = conn.getConten