集册 Java实例教程 通过URL获取远程文件大小

通过URL获取远程文件大小

欢马劈雪     最近更新时间:2020-01-02 10:19:05

45
提示:您可在线编辑运行本教程的实例 - 运行实例,去试试!
通过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
展开阅读全文