1 import java.net.URL;
2 import java.net.URLConnection;
3 import java.text.DecimalFormat;
4
5 /*
6 计算指定URL的文件大小
7 */
8 public class FlowTool{
9 public static void main(String[] args)throws Exception{
10 URL url = new URL("http://www.baidu.com");
11 URLConnection uc = url.openConnection();
12 String fileSize = new DecimalFormat("0.00").format((float) uc.getContentLength() / 1024);
13 System.out.println("文件大小:"+fileSize+"KB");
14 }
15 }